Matlab GUI. How can i make an animated dot in a parabola in a 1 by 1 plane?

1 回表示 (過去 30 日間)
Hi everyone, I need help to do an animated dot. but instead of a straight line, i need to do it in a parabola in a 1 by 1 plane. How can I code this?
  3 件のコメント
Image Analyst
Image Analyst 2019 年 4 月 4 日
Not sure what a 1 by 1 plane, but did you try plotting with just . instead of -?
Instead of
plot(x, y, 'b-');
try
plot(x, y, 'b.', 'MarkerSize', 18);
Ariel Goya
Ariel Goya 2019 年 4 月 4 日
i am sorry, i meant in a x and y axes plane. so far i made the dot to move in a straight line, but i need it to move in a parabola.
a = [0, 0];
b = [ 1 , 1];
% straight line function from a to b
func = @(x)b(1) + (b(1)-a(1))/(b(1)-a(1))*(x-b(1));
% determine the x values
x = linspace(a(1),b(1),800);
% determine the y values
y = func(x);
% create the figure
figure;
% get a handle to a plot graphics object
hPlot = plot(0,0,'r*');
% set the axes limits
xlim([min(a(1),b(1)) max(a(1),b(1))]);
ylim([min(a(1),b(1)) max(a(1),b(1))]);
% iterate through each point on line
for k=1:length(x)
% update the plot graphics object with the next position
set(hPlot,'XData',x(k),'YData',y(k));
% pause for 0.5 seconds
pause(0.005);
end

サインインしてコメントする。

採用された回答

Andreas Bernatzky
Andreas Bernatzky 2019 年 4 月 4 日
Hey Ariel,
with a 1by1 plane you mean a simple xy plane?
Here a rough example. You should consider the command draw now.
x=-10:0.1:10;
y=x.^2+x+1;
for(xmom=x(1):0.1:10)
plot(x,y);
hold on
ymom=xmom.^2+xmom+1;
plot(xmom,ymom,'-o');
pause(0.1);
clf;
end
  2 件のコメント
Ariel Goya
Ariel Goya 2019 年 4 月 4 日
Thank you Andreas, it worked i just need to plot an image instead of a dot, and also i need the line to be transparent.
Andreas Bernatzky
Andreas Bernatzky 2019 年 4 月 4 日
Ploting an image with variable position I am not really familiar with this. I just used
https://de.mathworks.com/help/images/ref/imshow.html once and it worked for me. But my application had not a moving image. But I think you should be able to manipulate the image position by the Position handle of an object in a figure. Thats what I would try first.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by