graph2d package cannot be found
显示 更早的评论
Hi, I tried to plot horizontal lines using graph2d.constantline function. It worked well with R2014a, but not any more since I upgraded to R2014b. Matlab does not seem to find graph2d package:
hy = graph2d.constantline(0, 'LineStyle','-', 'Color','r'); changedependvar(hy,'y');
Undefined variable "graph2d" or class "graph2d.constantline".
I did have graph2d package installed. Is there a way to fix this problem? There is an answer about installing Matlab from a network drive. But I install my Matlab on my computer directly. Thanks.
回答(1 个)
Star Strider
2014-10-25
I didn’t realise it existed. (It was an undocumented function through R2014a, apparently, as referred to here.) It doesn’t exist in R2014b, gone with a lot of other graphics functionality that is no longer available in HG2. (That’s why I’m keeping R2014a and its more flexible graphics.)
It’s easy enough to plot a horizontal line. This plots one at y=5:
figure(1)
plot(-2:5, (-2:5).^2-1)
hold on
plot(xlim, [5 5]) % Plot Horizontal Line
hold off
2 个评论
Star Strider
2014-10-25
WY’s Answer moved here...
Thanks. But graph2d does come with other packages of 2014b. It is usually located in /toolbox/matlab/graph2d. So my question was actually why Matlab does not recognize it. Maybe you are right. With the graphics upgrade in 2014b, this is probably no longer supported although it is installed.
graph2d.constantline is very convenient because you don't have to care about the limits of your axes.
Star Strider
2014-10-25
My pleasure!
You don’t have to care about the limits of your axes without it, if you use xlim (or ylim) to define them, as I did in my example. I simply defined the x-coordinates using xlim, and a two-element vector (here [5 5]) to plot it at the desired y-value. If for any reason xlim changes, the line’s x-coordinates automatically change as well.
类别
在 帮助中心 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!