Problem with reaching specific values of an array or matrix

조회 수: 1 (최근 30일)
Go Sugar
Go Sugar 2022년 8월 15일
편집: Go Sugar 2022년 8월 15일
Hello. I have a for loop, for each value of counter, I want to find the relevent raw value when rs==1 or ep==1 from various excel files.
If rs==1, I want it to write t_c's relevant value corresponding its raw value.
If ep==1, I want it to write t_c's relevant value corresponding its raw value + 1.
However, when I consider raw value + 1, I get zero values (even without if loop). I do not understand why this happens so? When I try to find its relevant value for raw value, I get true values (without the if loop). I would be happy if I solved this question.Thank you. :)
Below is a part of my code:
ep=mydata(:,1);
counter=mydata(:,2);
rs=mydata(:,3);
t_c=mydata(:,4);
t=[];
raw=[];
for n=0:4
f=1;
raw(f)=find((counter == n) & ((rs==1) | (ep==1)))
y(f)=raw(f)+1
if (rs==1)
te(f)=t_c(raw(f))
else (ep==1)
te(f)=t_c(y(f))
end
t=[t te(f)]
C=table(t);
f=f+1;
end
  댓글 수: 7
dpb
dpb 2022년 8월 15일
I'd suggest posting your final code as an Answer, then -- you can Accept your own. Serves to let folks know the problem is sovled if nothing else.
Go Sugar
Go Sugar 2022년 8월 15일
Ok, I have just posted it. Thank you so much for the quick replies. :)

댓글을 달려면 로그인하십시오.

채택된 답변

Go Sugar
Go Sugar 2022년 8월 15일
편집: Go Sugar 2022년 8월 15일
This is the finalized version of the code. It is working as expected. Thank you for all the help. :)
ep=mydata(:,1);
counter=mydata(:,2);
rs=mydata(:,3);
t_c=mydata(:,4);
a=mydata(:,5);
t=[];
raw=[];
for n=0:4
f=1;
raw(f)=find((counter == n) & ((rs==1) | (ep==1)));
y(f)=raw(f)+1;
if (a==0)
te(f)=t_c(raw(f));
else
te(f)=0;
end
t=[t te(f)]
C=table(t);
f=f+1;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by