Looping through cell array in order
显示 更早的评论
I'm drawing squares on a grid. The squares need to have an ID as set within a cell array. I was expecting the ID to loop through each ID in the cell in order by instead it cycles through in rows.

 
cell_id = cell(1, 2); % 1 x 5 cell array
cell_id{1, 1} = 1365;
cell_id{1, 2} = 1256;
cell_id{1, 3} = 6214;
cell_id{1, 4} = 2587;
cell_id{1, 5} = 1564;
hold on
for i = 1:2:12
count = 1;
for ii = 1:2:12
plot(1*i , 1*ii, 's', 'MarkerSize', 50);
if (count <= 5)
id = cell_id(1,count);
text(1*i, 1*ii, ['ID:',id]);
count = count + 1;
elseif (count > 5)
id = cell_id(1,1);
count = 1;
text(1*i, 1*ii, ['ID:',id]);
end
end
end
Any ideas, thanks.
1 个评论
per isakson
2014-12-10
编辑:per isakson
2014-12-10
- Do you expect 4 rows times 6 columns of boxes?
- Replace i by xx and ii by yy or something associated with directions
- Set the axes limits before adding the boxes. It's confusing that the limits change all the time
- And format the code properly. (I did it this time.)
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
