How to repeat the same graph?

조회 수: 27 (최근 30일)
Donghun Lee
Donghun Lee 2020년 8월 5일
댓글: Star Strider 2020년 8월 6일
clc, clear all
%% Road profile
% spatial frequency (n0) cycles per meter
Omega0 = 0.1; %%%%conventional value of spatial frequency(n0)?
% psd ISO (used for formula 8)
Gd_0 = 32 * (10^-6);
% waveviness
w = 2;
% road length
L = 250;
%delta n
N = 100;
Omega_L = 0.004;
Omega_U = 4;
delta_n = 1/L; % delta_n = (Omega_U - Omega_L)/(N-1);
% spatial frequency band
Omega = Omega_L:delta_n:Omega_U;
%PSD of road
Gd = Gd_0.*(Omega./Omega0).^(-w);
% calculate amplitude using formula(8) in the article
%Amp = sqrt(2*Gd*delta_n); %%%from Eq. 7?
%calculate amplitude using simplified formula(9) in the article
k = 3; %%%upper limit A and lower limit B k=3?
%Amp = sqrt(delta_n) * (2^k) * (10^-3) * (Omega0./Omega);
Amp = sqrt(delta_n) * (2^k) * (10^-3) * (Omega0./Omega);
%random phases
Psi = 2*pi*rand(size(Omega));
% x abicsa from 0 to L
x1 = 0:250/(N-1):250;
h= zeros(size(x1));
%artificial random road profile
for iv=1:length(x1)
h(iv) = sum( Amp.*cos(2*pi*Omega*x1(iv) + Psi) );
end
hx = [x1' h'];
%% ode45
y0 = [0,0];
[t, y] = ode45(@f,x1,y0,[],hx);
%% plot
figure
plot(t,y(:,1));
xlabel('time'),ylabel('vertical displacement')
function dydt = f(t,y,hx)
k_s = 26400; %spring stiffness
m = 483; %Mass
v = 50/9; % speed along road
x = v*t;
hs = hfn(x,hx);
dydt =[y(2);
-( k_s*(y(1)-hs)/ m )];
end
function hs = hfn(x, hx)
hs = interp1(hx(:,1),hx(:,2),x);
end
Hi, I wish to repeat the same graph like several times in one graph. Here's the example below,
Thanks for reading
  댓글 수: 2
MADRobot
MADRobot 2020년 8월 5일
If you use 'hold on', you should then be able to plot on the same figure, then simply use the 'hold off' function when you're done plotting on the same graph.
For example:
%% plot
figure
plot(t,y(:,1));
hold on
plot(A,a(:,1)); % another plot you want to assign to the same figure
plot(B,b(:,1)); % another plot you want to assign to the same figure
%............. etc
plot(X,x(:,1)); % another plot you want to assign to the same figure
hold off
% Anything you 'plot' here (after writing 'hold off') won't be plotted on the same figure
Please let me know if this doesn't make sense and I'll try to ellaborate/ show you some examples
Donghun Lee
Donghun Lee 2020년 8월 6일
Thank you so much! It was really helpful and I appreciate it!

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

채택된 답변

Star Strider
Star Strider 2020년 8월 5일
Try this:
t = 0:40;
y = exp(-0.385*t) + 10;
y6 = repmat(y, 1, 6);
t6 = 0:numel(y6)-1;
figure
plot(t6, y6)
grid
producing:
.
  댓글 수: 2
Donghun Lee
Donghun Lee 2020년 8월 6일
It’s such a nice approach! Thank you so much!!
Star Strider
Star Strider 2020년 8월 6일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by