Clear Filters
Clear Filters

How to put a list of different arrays, one after another, to create a new array ?

3 views (last 30 days)
What I am asking is similar to this example,
I have y1,y2,y3 manually created and I want my final array to be
data = [y1,y2,y3];
How am i supposed to do the same thing inside a for loop ?
for i=1:10
y = myfunc();
data = ??
end
I hope you understood what I cant do and I sincerely hope this can be done someway.
P.S.: I am aware of allocating memory space for the dynamically created array data
Thanks for your time in advance !

Accepted Answer

Matt J
Matt J on 14 May 2013
You haven't said whether y1,y2,y3 are scalar or not. If not,
data=cell(1,10);
for i=1:10
data{i} = myfunc();
end
y=[data{:}];
  3 Comments

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 14 May 2013
Edited: Azzi Abdelmalek on 14 May 2013
for i=1:10
y = myfunc();
data(i)= y
end

Categories

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

Community Treasure Hunt

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

Start Hunting!