how can i write code for animating the plots when i use column vector.

i have two sets of data.
surge amplitude and tension magnitude. the time steps are different but the time for both starts at 0 to 10800 s.
i am trying to have a n animated plot of both data (surge and tension)

2 件のコメント

Rik
Rik 2021 年 5 月 26 日
Have a read here and here. It will greatly improve your chances of getting an answer.
What have you tried? What is your specific question?
Iman Ramzanpoor
Iman Ramzanpoor 2021 年 5 月 27 日
編集済み: KSSV 2021 年 5 月 27 日
Hi,
To animate a plot, I wrote the below code but does not work. I do not know much about MATLAB coding. How can I write a code to animate a multiplot (surge and tension).
t = TIME1;
y = tension;
t2 = TIME2;
y2 = surge;
For k = 1:length(t)
k2 = 1:length(t2)
%% marker plots
plot(t(k),y(k),'x')
hold on
plot(t2(k2),y2(k2),'o')
hold on
%% line plots
plot(t(1:k),y(1:k))
hold on
plot(t2(1:k2),y2(1:k2))
if k ~= length(t)
k2 ~= length(t2)
clf
end
end

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

回答 (2 件)

KSSV
KSSV 2021 年 5 月 27 日

0 投票

Let (t1,x1) and (t2,x2) be your data. Where x1 is surge and x2 is tension. Both t1, t2 are in same intervel.
First let's get them to same time t1 using interpolation.
x2 = interp1(t2,x2,t1) ;
Now you can plot them.
for t = 1:length(t1)
plot(t1(1:t),x1(1:t),'r',t2(1:t),x2(1:t),'b') ;
drawnow
pause
end
You can also use set, this will be the good option. Read about it.

7 件のコメント

Iman Ramzanpoor
Iman Ramzanpoor 2021 年 5 月 27 日
thanks,
still have issue. i wrote the way you recommended as below but get error.
t = t1;
y = tension;
t2 = t2;
y2 = surge;
t3 = interp1(t2,surge,t1) ;
for t = 1:length(t1)
plot(t1(1:t),y(1:t),'r',t2(1:t),y2(1:t),'b') ;
drawnow
pause
end
Error using griddedInterpolant
Sample points must be unique.
Error in interp1 (line 170)
F = griddedInterpolant(X,V(:,1),method);
KSSV
KSSV 2021 年 5 月 27 日
It seems your t2 data is not unique/ continuous. Attach your data.
Iman Ramzanpoor
Iman Ramzanpoor 2021 年 5 月 27 日
hi,
thank you very much. please find the attached excel sheet.
KSSV
KSSV 2021 年 5 月 27 日
The range of each data is completely different.....
Iman Ramzanpoor
Iman Ramzanpoor 2021 年 5 月 27 日
the range is the same, but the time step is different. the other way is to animate plot individually. so
if possible, please let me know how to set up animated plot for one then. it would be a great help. i am using column vectors to import the data to MATLAB.
cheers
KSSV
KSSV 2021 年 5 月 27 日
for t = 1:length(t1)
plot(t1(1:t),x1(1:t),'r') ;
drawnow
pause
end
Also have a look on comet.
Iman Ramzanpoor
Iman Ramzanpoor 2021 年 5 月 27 日
Thanks, it still does not work.
By having the data I have sent to you, how do you write the complete code which creates an animated line of surge or tension.

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

Iman Ramzanpoor
Iman Ramzanpoor 2021 年 6 月 14 日

0 投票

how to slow the speed the animated graph?

カテゴリ

ヘルプ センター および File ExchangeAnimation についてさらに検索

タグ

質問済み:

2021 年 5 月 26 日

回答済み:

2021 年 6 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by