help with preallocating arrays?

i need help making making this preallocated array
myArray = []
variableArray = []
for i=1:10
variable = [1,2,3]
variableArray = [variable]
myArray = [myArray; variableArray]
end

Antworten (1)

Roger Stafford
Roger Stafford am 10 Apr. 2015

1 Stimme

myArray = zeros(1,10);
for k = 1:10
myArray(k) = k+1;
end
or better still:
myArray = 2:11;

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

ME
am 10 Apr. 2015

Bearbeitet:

ME
am 12 Apr. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by