How to save and plot in same figure data from the loop iteration ?

2 visualizaciones (últimos 30 días)
I have this function: I need to plot loop iteration of gama value in the same figure at the end gama= [1.20,2.90,3.1,4.4,5.3] for gama= %all in the same figure end please need help

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 23 de Oct. de 2018
Editada: KALYAN ACHARJYA el 23 de Oct. de 2018
for i=1:number_of_iterations
%Do operations
plot();
hold on;
end
In your case
gama=[1.20,2.90,3.1,4.4,5.3];
for i=1:length(gama)
gama=gama(i);
%do operations
Plot();
hold on;
end
  3 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 23 de Oct. de 2018
Editada: KALYAN ACHARJYA el 23 de Oct. de 2018
Can you provide the code in the proper format (use {} in text format section), so that it can easily readable?
Fabrice shao
Fabrice shao el 23 de Oct. de 2018
clear;
% p0=2;Input power in (w)
p0=6
% p0=5
T1=5;% Pulse with
T0=T1/2/sqrt(log(2));%(FWHM)
h=1;%²½³¤
% gama=2.90
% for gama=[1.20, 2.90 ,3.1]
% gama = 2:0.1:10;gama=[1.20,2.90,3.1,4.4,5.3];
% gama=[1.20,2.90,3.1,4.4,5.3];
for gama=[1.20,2.90,3.1,4.4,5.3];
% do operations
% Plot();
hold on;
end
beta=0;%%second order dispersion
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*p0*(t/T0).*exp(-(t/T0).^2);
for k=1:10
u0=usz;
usz=abs(u0).*exp(-h*j*gama*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)
% plot(t,A0.^2,'g');
hold on
figure (100)
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])
% figure (2);
% plot(t,(abs(Az).^2),'b');%´«ÊäLºóÐźŹ¦Âʲ¨ÐÎ*2/N
% plot (3)
% plot(f,fftshift((T*abs(fft(uszgz0))).^2)/N,'g');%³õʼÐźŹ¦ÂÊÆ×
% figure (4)
% plot(f,(T*(abs(fusz))).^2/N,'b','Linewidth',4);%´«²¥100kmºóµÄÐźŹ¦ÂÊÆ×
% title('Pulse Evolution');
% xlabel('Wavelenght(u) ');
% ylabel('Power (W)');
% set(gca,'FontSize',24);
% legend ('Wavelenght');
% % legend boxon
% % grid on;
% % xlim([-800,800])% figure (5)
% plot(t/T0,dfait,'g');%ÀíÂÛßúà±
% figure (6)
% plot(t(2:N)/T0,diff(angle(usz))/T,'b');%fft
figure (7)
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 ('1m','2m','3m','4m','5m');
legend boxon
grid on;
xlim([-900,900])
grid on
end

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by