How do you start a new column for every iteration in a loop?
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!