Graph Updates but does not display Line
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
When I run this code to update the graph in an animation like manner, the axis of the graph updates, indicating that the new data has been received, but the new line is not plotted. It is as almost like everything is working but the color does not appear.
plot(x,y,'--r','LineWidth',3); % original position
xlabel('Beam Length (in.)','Color','b');
ylabel(bstr,'Color','b');
%ylim([-(Beam.y(10)) max(Beam.y)]);
title(astr,'Color','y','fontweight','b');
set(S.ax,'YDir','reverse');
set(S.ax,'XGrid','on');
set(S.ax,'YGrid','on');
xZero = 0;
yZero = 0;
hold on % hold the orginal position plot and the axes properties
M(100) = struct('cdata',[], 'colormap', []); % preinitialization
ht = plot(xZero,yZero,'-b','linewidth',2); % new position
set(ht ,'XDataSource','Beam.x') % Sets the data source for plot ht
set(ht,'YDataSource','Beam.y')
for a1 = 1:100
for i = 1:100 % Plots each new position on the graph
set(ht,'XData',Beam.x(i))
set(ht,'YData',Beam.y(a1,i))
end
M(a1) = getframe(gcf); %The plot seems to adjust proeperly
end
0 comentarios
Respuestas (1)
Ryan Livingston
el 8 de En. de 2013
I wasn't able to run your code due to some undefined variables but here are a few thoughts:
'-b'
is specified as the linespec which will plot a tiny dot on the axes. Could you try:
'-b*'
to plot a larger marker and see if that moves?
- When calling set(ht, 'XData'...) it seems that each new plot will be a single point. Is this what you wanted or did you want to accumulate the points? - If these don't help could you please post a code snippet which has all the variables defined and runs on its own?
~Ryan
2 comentarios
Ryan Livingston
el 9 de En. de 2013
That helps a bit. My assumption is that:
Beam.x(i), Beam.y(a1,i)
are scalars, is that correct? In that case, a single point is being plotted rather than a line.
If you would like to plot one row of y versus x then does something like:
set(ht,'XData',Beam.x(i))
for a1 = 1:100
set(ht,'YData',Beam.y(a1,:))
M(a1) = getframe(gcf); %The plot seems to adjust properly
end
do more what you are looking for rather than the two nested loops?
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!