Why the for-loop doesn't work here?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!