How to plot data with >2 dimensions?
17 次查看(过去 30 天)
显示 更早的评论
I have a variable of size 3x5x10000 and I want to plot this. The idea is that there are 5 trees which grow over 10000 timesteps in 3 different scenarios.
How could I get this in a plot which shows the growth of 5 trees over 10000 timesteps in 1 plot, and have 3 plots in total for each different scenario? The plot function can seemingly only use data with 2 dimensions.
0 个评论
回答(2 个)
Rik
2020-10-12
Apart from plot3 (as Alan suggested), you may also consider using subplot to divide the different scenarios and using hold to plot the multiple trees in a single axes (or the reverse of course). The fact that your variable is 3D doesn't mean you need to actually plot your data in 3 dimensions.
2 个评论
Rik
2020-10-12
编辑:Rik
2020-10-12
Use dh(1,1,:) instead, that will select the first element from each 3x5 block. If plot still complains, use squeeze to reduce the dimensionality of your array.
dh=rand(3,5,10000);
time=1:size(dh,3);
n=0;
for scenario=1:size(dh,1)
ax=subplot(1,3,scenario);
cla(ax);%only for debugging: clear axes contents
hold(ax,'on');
for tree=1:size(dh,2)
name=sprintf('tree %d',tree);
plot(time,squeeze(dh(scenario,tree,:)),'DisplayName',name,'Parent',ax);
end
hold(ax,'off');
title(sprintf('scenario %d',scenario))
legend(ax)
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!