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

回答 (1 件)

Roger Stafford
Roger Stafford 2015 年 4 月 10 日

1 投票

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

ME
2015 年 4 月 10 日

編集済み:

ME
2015 年 4 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by