我有这样的代码;
figure;
for a = 1:length(weekM')
tday_cell = day_cell(week_cell == weekM(a));
for b = 1:length(days)
subplot(length(weekM'), 7, b);
if strcmp(first_entranceM{a, b}, '0')
plot(peaks);
l = [l; 0];
else
tms_cell = ms_cell(week_cell == weekM(a));
ttms_cell = tms_cell(strcmp(tday_cell,days{b}));
l = [l; ttms_cell];
plot(ttms_cell);
end
end
end
我想将带有子图功能的图绘制为subplot(3,7,[1:2:3...])
。也就是说,我想绘制图表,其中每行有3行和7个图表。
但在我的情况下,它只显示第一行的最后一行,而我看不到其余的图。
我确定用于绘制以前图表的数据不会丢失,但我不明白为什么会丢失图表。
你能帮我解决这个问题吗?
答案 0 :(得分:1)
需要更改subplot
语句的行。第一个论点是正确的。第二个参数表示列数,需要在此处设置为7,因为您有7天。最后一个参数是被寻址的子图的索引,需要在每次迭代中进行更改。
可以使用sub2ind
- 函数生成此索引,该函数根据下标计算索引。可以使用以下行代替您的行:
subplot(length(weekM'),7,sub2ind([7,length(weekM')],b,a));