Create Variables with a for loop

3 views (last 30 days)
Shani Gal
Shani Gal on 25 Feb 2012
Hi
I need to be able to run this following code:
Vx(1)=[0,0,12]
Vx(2)=[12,1,1,1,]
Etc
I need Vx to be a vector but with different number of element.
( I can write Vx1 Vx2 etc but I have 1000 elements and it is tedious, the inputs are entered from a different subroutine so I am hoping to be able to do it with a for loop)
Can this be done?
Thanks
Shani

Answers (2)

Oleg Komarov
Oleg Komarov on 25 Feb 2012
You can use cell arrays, where each cell will contain an array of potentially differrent size.
An example:
c = cell(10,1)
for ii = 1:10
c{ii} = rand(ii);
end

Walter Roberson
Walter Roberson on 25 Feb 2012

Categories

Find more on Introduction to Installation and Licensing 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!