How "hold on" function works?
39 次查看(过去 30 天)
显示 更早的评论
hi everyone. i have a problem with "hold on" function.
I need to plot many lines to "axes" in matlab gui. I'm using "hold on" to keep all the lines on the graph, but there's a problem. I read on "hold on documentation" that:
"MATLAB® adjusts axes limits, tick marks, and tick labels to display the full range of data."
but if i plot a set of data that has, for example, a range on the x-axis that goes from 1000 to 1200 i visualize the line on the graph, then, if i plot another set of data that goes from 3000 to 4000, the range of x-axis still remain the previous one (1000-1200), so i can't visualize the second line.
How can i hold all the lines on the graph that i plot with x-axis that automatically update the range?
0 个评论
回答(3 个)
Walter Roberson
2019-2-18
After you
hold on
you can do
ax = gca;
set(ax, 'XLimMode', 'auto', 'YLimMode', 'auto')
before you draw the new items.
Note: if you set XLimMode or YLimMode to auto after you have added the new data, then MATLAB will typically not rescan the data to determine what it should use.
0 个评论
Kevin Doherty
2015-10-2
编辑:Kevin Doherty
2015-10-2
I'm not sure if there is a direct way to tell Matlab to update the axes to include all the plots. But you could use the axis function to return the limits of each plot. Then, after you've plotted everything, you could update the axes in order to view everything. For example,
t1 = 0:10;
x1 = 2*t1;
t2 = 5:15;
x2 = t2+1;
plot(t1,x1)
a(1,:) = axis; % save axis values as a row of the matrix a
hold on
plot(t2,x2)
a(2,:) = axis;
axis([min(a(:,1)) max(a(:,2)) min(a(:,3)) max(a(:,4))]); % update the current axes to include the full ranges of the axes from all the plots so far
0 个评论
Matlaber
2019-2-18
Is "hold on" function only work in plotting?
csvwrite('1test.csv',a, 0,1);
hold on;
csvwrite('1test.csv',b, 0,2);
It seemed not working as I want to input multiple input into a same/similar/one csv file
2 个评论
Walter Roberson
2019-2-18
"hold on" has no connection at all to csvwrite().
csvwrite() can never append to an existing file. csvwrite() is a simplified interface to dlmwrite(). dlmwrite() itself includes an option to append.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Labels and Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!