lm having a problem with code for dispersion when ever l try to run, it say the variable 'dispersion' in line 20 is changing the size of every loop so how do l solve this
3 ビュー (過去 30 日間)
古いコメントを表示
clc;
clear all;
close all;
format long;
wl=1:0.05:2;
wl1=wl*1e-6;
vc=299792458;
w=2*pi*(vc./wl1);
Wavelength=wl*1e-6;
Fresult={'ofc_y.txt', 'ofc_x.txt'};
for i=1:2
[neff,beta,alpha,alphadB]=textscan(Fresult{i},....
'%f %f %f %f');
beta(i,:)=beta;
alpha(i,:)=alpha;
alphadB(i,:)=alphadB;
b1=diff(beta(i,:))./diff(w);
Dispersion(i,:)=((diff(b1)./diff(wl1(1:end-1))));
end
figure(1)
plot(wl1*1e6,neffr(1,:),'-r',wl1*1e6,neffr(2,:),'-b');
legend('y-mode','x-mode','Location','best');
xlabel('Wavelenght(\mu m)');
ylabel('Effective Index');
title('Effective Index vs wavelength');
figure(2)
plot(wl1*1e6,betar(1,:),'-r',wl1*1e6,betar(2,:),'k');
legend('y-mode','x-mode','Location','best');
xlabel('Wavelenght(\mu m)');
ylabel('beta');
title('beta vs wavelength');
figure(3)
plot(wl*1e6,alphadBr(1,:),'-r',wl*1e6,alphadBr(2,:),'k');
legend('y-mode','x-mode','Location','best');
xlabel('Wavelenght(\mu m)');
ylabel('alphadB');
title('alphadB vs wavelength');
figure(4)
plot(wl1(1:end-2)*1e6,Dispersion(1,:),'-r',wl1(1:end-2)*1e6,Dispersion(2,:),'k');
legend('y-mode','x-mode','Location','best');
xlabel('Wavelenght(\mu m)');
ylabel('Dispersion');
title('Dispersion vs wavelength');
0 件のコメント
採用された回答
Abderrahim. B
2022 年 7 月 23 日
Hi!
I beleive that s only a warning, to avoid it preallocate for Disperssion variable.
Demo:
Without preallocation :
A = randi(10,20,20) ;
for ii = 1:20
B(ii, :) = A(ii, :) ;
end
B
With preallocation:
B = zeros(size(A)) ; % preallocation for B using function zeros
for ii = 1:20
B(ii, :) = A(ii, :) ;
end
B
Hope this helps
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!