How to set different y limits for multiple subplots?
142 次查看(过去 30 天)
显示 更早的评论
I have 12 subplots that I am trying to plot, but when I plot them the axes are all messed up. I would like to set the y-axis based on the min and max value of the data that I am plotting, but I get this error when trying to set the limits
Subscript indices must either be real positive integers or logicals.
This is my code:
for i=1:length(idx)
subplot(4,3,i);
plot(DLG.Data{1,1}(:,1),DLG.Data{1,1}(:,idx(i)));
xlim([0 250]);
min = min(DLG.Data{1,1}(:,idx(i)));
max = max(DLG.Data{1,1}(:,idx(i)));
ylim([min max]);
end
The xlimits are always the same, the only thing that change are the y-limits.
0 个评论
回答(2 个)
Giuseppe Naselli
2018-2-21
if you use the handle of each sub plot you will have much more freedom (and less issues :) ) for example
subplot1 = subplot(4,3,1) %get the handle of this subplot/axis
plot(x,y,'Parent',subplot1) % (see the use of parent-child relationship?)
xlim(subplot1,[min max]); % assign your limits only to that specific subplot
repeat in a loop or for each one as you wish. Using handles makes life much easier G
0 个评论
Santhana Raj
2017-5-31
Your mistake is to use the function name as a variable. "min"
The first loop will work. where you use the min function to get the value and store it in min. This overwrites the function min. The next iteration will throw the error. Same happens for Max also.
Try with different variable name for min and max....it should work fine.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!