Why the for-loop doesn't work here?

1 visualizzazione (ultimi 30 giorni)
Wiqas Ahmad
Wiqas Ahmad il 11 Mag 2021
Commentato: KSSV il 11 Mag 2021
close all;
clear all;
clc;
%% ------------------------------Program-------------------------------------
z=2860:11:3135;
FOV=[1 2];
i_in = getsignal(['FOV_',num2str(FOV(1)),'mrad\out_resultsG_I0.dat']);
q_in = getsignal(['FOV_',num2str(FOV(1)),'mrad\out_resultsG_Q0.dat']);
i_out = getsignal(['FOV_',num2str(FOV(2)),'mrad\out_resultsG_I0.dat']);
q_out = getsignal(['FOV_',num2str(FOV(2)),'mrad\out_resultsG_Q0.dat']);
I_in = sum(i_in,2);
Q_in = sum(q_in,2);
I_out = sum(i_out,2);
Q_out = sum(q_out,2);
dep_in = (I_in-Q_in)./(I_in+Q_in);
dep_out = (I_out-Q_out)./(I_out+Q_out);
figure,
hold on
plot(dep_in,z);
plot(dep_out,z);
figure,
hold on
plot(dep_in./dep_out,z);
I converted this program into for-loop as:
close all;
clear all;
clc;
%% ------------------------------Program-------------------------------------
z=2860:11:3135;
FOV=[1 2];
for i=1:length(FOV)
I0 = getsignal(['FOV_',num2str(FOV(i)),'mrad\out_resultsG_I0.dat']);
Q0= getsignal(['FOV_',num2str(FOV(i)),'mrad\out_resultsG_Q0.dat']);
I(i) = sum(I0(i),2);
Q(i) = sum(Q0(i),2);
dep(i) = (I(i)-Q(i))./(I(i)+Q(i));
figure,
hold on
plot(dep(i),z);
end
figure,
hold on
plot(dep(1)./dep(2),z);
The program has no error but now it doesn't display the plots. I need some correction to this program

Risposte (1)

KSSV
KSSV il 11 Mag 2021
You save all the values into an array and plot after the for-loop.
%% ------------------------------Program-------------------------------------
z=2860:11:3135;
n = length(FOV) ;
FOV=[1 2];
I = zeros(1,n) ;
Q = zeros(1,n) ;
dep = zeros(1,n) ;
for i=1:n
I0 = getsignal(['FOV_',num2str(FOV(i)),'mrad\out_resultsG_I0.dat']);
Q0= getsignal(['FOV_',num2str(FOV(i)),'mrad\out_resultsG_Q0.dat']);
I(i) = sum(I0(i),2);
Q(i) = sum(Q0(i),2);
dep(i) = (I(i)-Q(i))./(I(i)+Q(i));
end
figure,
plot(dep,z);
  2 Commenti
Wiqas Ahmad
Wiqas Ahmad il 11 Mag 2021
I solved it. Thank you for your comments
KSSV
KSSV il 11 Mag 2021
Thanks is accepting/ voting the answer.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by