How do you start a new column for every iteration in a loop?

2 ビュー (過去 30 日間)
T Shep
T Shep 2016 年 12 月 1 日
編集済み: Alexandra Harkai 2016 年 12 月 1 日
I am loading trying to store each iteration in a separate column in: percent(j,:)=[percent_correct].
There should be a total of 11 columns with 50 rows. However, only the last 50 values are stored.
sid = 'data_x';
for ii = 1:11
load([sid,num2str(ii),'.mat'])
for j = 1:50
num_words= numel(q.data.sent{j})
num_correct=data(j,4)
percent_correct=num_correct/num_words
percent(j,:)=[percent_correct]
end
end

採用された回答

Alexandra Harkai
Alexandra Harkai 2016 年 12 月 1 日
編集済み: Alexandra Harkai 2016 年 12 月 1 日
If data is a 2-dimensional array then percent_correct is a scalar so you need to make sure it is saved in one exact place in the percent array.
Also it helps if you preallocate the matrix before the loop:
rows = 50;
cols = 11;
percent = zeros(rows, cols);
for ii = 1:cols
...
for j = 1:rows
...
percent(j, ii)=[percent_correct];
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by