Graph Updates but does not display Line

1 visualización (últimos 30 días)
Lawson Hoover
Lawson Hoover el 8 de En. de 2013
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

Respuestas (1)

Ryan Livingston
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
Lawson Hoover
Lawson Hoover el 9 de En. de 2013
Editada: Lawson Hoover el 9 de En. de 2013
I wish I could give you all of the variables but there is alot of other code to get those values, and a very large matrix that is used for the y values.
I tried your '-b*' method and I can see a dot on the graph now, the dot appears at the very tip of the line, and is adjusting accordingly, but still no actual line.
It seems like it is not plots the x values. and the goal of this is that in the for loops at the bottom, is that it will run a row with 100 y values and plot it, then store the plot in M for the movie and then plot the next 100 y values. The way y is stored is in a 100x100 matrix where each row is a new set of 100 y values.
Ryan Livingston
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?

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by