How to successively fill a matrix using a for loop?

Hello,
I'm relatively new to Matlab, and would appreciate some assistance on this issue. I have a large cell of data called 'ABS' (acoustic backscatter sensor) that is 4x16, and each cell contains a 256x1800 double. In words, this is 4 instrument channels by 16 bursts of data. Each burst for each channel consists of 256 vertical bins and 1800 individual profiles. My goal is to create a new matrix called 'timeseries' that is 256 rows by 1800*16=28800 columns in length, in order to plot the entire timeseries of data at once (all vertical bins, and all profiles for all successive bursts).
I first planned to do it this way:
timeseries=horzcat(ABS{1,1},ABS{1,2},ABS{1,3},...,ABS{1,16};
It works, but will be cumbersome when I need to do this with more than 16 bursts (say, 1000 bursts). Is there a way to write a loop to fill in a matrix automatically? I started with the following, where numprofiles is 1800 in this example case, and numbursts is 16. But I couldn't figure out what to write where the ??s are.
timeseries=zeros(256,numprofiles*numbursts); %preallocate matrix
for i=1:numbursts
timeseries(:,?????)=ABS{1,i};
end
Any help would be greatly appreciated, and let me know if anything isn't clear. Thanks for your time!

 Accepted Answer

In one line:
TS = horzcat(ABS{1,:});

2 Comments

Why I didn't think of that, I haven't the slightest. Thank you!
@Kevin Simans: using MATLAB is sometimes a bit like herding cats... but it also has its moments of brilliance :)

Sign in to comment.

More Answers (1)

% -------Example-------
M=cell(4,16);
M=cellfun(@(x) rand(256,1800),M,'un',0)
%------------The code------------
A=M(1,:);
out=[A{:}];

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 21 Jul 2016

Commented:

on 21 Jul 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!