# Why the for-loop doesn't work here?

1 view (last 30 days)
Wiqas Ahmad on 11 May 2021
Commented: KSSV on 11 May 2021
close all;
clear all;
clc;
%% ------------------------------Program-------------------------------------
z=2860:11:3135;
FOV=[1 2];
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)
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

KSSV on 11 May 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
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 CommentsShowHide 1 older comment
KSSV on 11 May 2021
Thanks is accepting/ voting the answer.