How to plot loop iteration in same figure
이전 댓글 표시
Hello all, I need to plot my gama for different instance loop iteration. This means I should save data for all loop and plot all in the same figure. Please see the following code. clear; gama=[1.20, 2.90 ,3.1] for gama ? end How to compute ?
댓글 수: 7
madhan ravi
2018년 10월 21일
편집: madhan ravi
2018년 10월 21일
What have we tried so far?
Fabrice shao
2018년 10월 24일
Kevin Chng
2018년 10월 24일
Not clear. plot(x,y) or plot(y)
for gama=[1.20,2.90,3.1,4.4,5.3]; % i dont understand this line
gama is your x or y?
Fabrice shao
2018년 10월 24일
편집: Fabrice shao
2018년 10월 24일
Kevin Chng
2018년 10월 24일
편집: Kevin Chng
2018년 10월 24일
Your gamma don't have any pattern
try this way.
gamma = [1.20 2.9 3.1 4.4 5.3]
%your for loop
for i=1:1:length(gamma)
end
inside the for loop, change all gamma to
gamma(i)
let me know if it is working for you. So, i post it in answer for your acceptance
Fabrice shao
2018년 10월 24일
편집: Fabrice shao
2018년 10월 24일
Kevin Chng
2018년 10월 25일
clear;
p0=6
T1=5;
T0=T1/2/sqrt(log(2));
h=1;
gama=[1.20,2.90,3.1,4.4,5.3];
for i=1:1:length(gama)
beta=0;
T=0.3;% total pulse with (TFWHM)
N=285;% Soliton order
n=-N/2:(N/2-1);
t=n.*T;% order
uszgz0=exp(-t.^2./(2*T0^2));
usz=exp(-t.^2./(2*T0^2));% Dispersion
A0=sqrt(p0)*uszgz0;% Amplitude
dfait=1/T0*h*gama(i)*p0*(t/T0).*exp(-(t/T0).^2);
%for k=1:10
u0=usz;
usz=abs(u0).*exp(-h*j*gama(i)*p0*(abs(u0).^2));%first order with Chirp parameter
fusz=fftshift(fft(usz));% Spectrum
end
f=(0:(N-1))./(N*T)*1e3-1/(2*T)*1e3;
Az=usz*sqrt(p0);%
figure(1)
hold on
plot(t,A0.^2,'b-o',t,A0.^2,'r.-','Linewidth',6)
title('Pulse Evolution');
xlabel('Time (ps) ');
ylabel('Power(W)');
set(gca,'FontSize',24);
legend ('Matlab IN','After SPM');
legend boxon
grid on;
xlim([-10,10];
hold off
figure(2)
hold on
plot(f,fftshift((T*abs(fft(uszgz0))).^2)/N,'g','Linewidth',6)
hold on
plot(f,(T*(abs(fusz))).^2/N,'b','Linewidth',4)
title('Pulse Evolution');
xlabel(' Frequency (GHz)');
ylabel('Power (W)');
set(gca,'FontSize',24);
legend ('Matlab IN','After SPM');
legend boxon
grid on;
xlim([-900,900])
grid on
hold off
end
%end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!