Why the for-loop doesn't work here?

1 回表示 (過去 30 日間)
Wiqas Ahmad
Wiqas Ahmad 2021 年 5 月 11 日
コメント済み: KSSV 2021 年 5 月 11 日
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

回答 (1 件)

KSSV
KSSV 2021 年 5 月 11 日
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 件のコメント
Wiqas Ahmad
Wiqas Ahmad 2021 年 5 月 11 日
I solved it. Thank you for your comments
KSSV
KSSV 2021 年 5 月 11 日
Thanks is accepting/ voting the answer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by