help with preallocating arrays?

1 次查看(过去 30 天)
ME
ME 2015-4-10
编辑: ME 2015-4-12
i need help making making this preallocated array
myArray = []
variableArray = []
for i=1:10
variable = [1,2,3]
variableArray = [variable]
myArray = [myArray; variableArray]
end

回答(1 个)

Roger Stafford
Roger Stafford 2015-4-10
myArray = zeros(1,10);
for k = 1:10
myArray(k) = k+1;
end
or better still:
myArray = 2:11;

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by