How do I plot time vs. velocity with a matrix in Simulink ?

조회 수: 1 (최근 30일)
Nuri Efe TATLI
Nuri Efe TATLI 2022년 5월 27일
편집: Sam Chak 2022년 5월 27일
Hi everyone.
I have a 1370x2 matrix where the first column is the time and second column is velocity.
I want to plot Time vs Velocity in x and y axis respectively.
Is there any block in Simulink that can help me with that ?
Thanks.

채택된 답변

Sam Chak
Sam Chak 2022년 5월 27일
In MATLAB, if a matrix M is given, then this would be:
t = M(:,1); % 1st column
V = M(:,2); % 2nd column
plot(t, V) % plotting V vs. t
However, in Simulink, it's a little complicated. Luckily, you can use a MATLAB Function block to do wonders.
Double-click the block and enter this code:
function plotfcn(u)
t = u(:,1);
V = u(:,2);
coder.extrinsic('plot')
plot(t, V, 'linewidth', 1.5)
grid on
xlabel('t')
ylabel('V')
  댓글 수: 2
Nuri Efe TATLI
Nuri Efe TATLI 2022년 5월 27일
편집: Nuri Efe TATLI 2022년 5월 27일
This is superb thank you very much.
Also can i create more than 1 figures with this on Simulink ?
Because only 1 figure appears when i run my simulation.
Sam Chak
Sam Chak 2022년 5월 27일
편집: Sam Chak 2022년 5월 27일
Yes you can.
function plotfcn(u)
t = u(:,1);
V = u(:,2);
coder.extrinsic('plot')
figure(1)
plot(t, V, 'linewidth', 1.5)
figure(2)
plot(t, sqrt(V), 'linewidth', 1.5)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by