Working with for loop

조회 수: 1 (최근 30일)
Tania Islam
Tania Islam 2020년 7월 6일
댓글: Tania Islam 2020년 7월 7일
Hi,
In my following code I want my final result ( final_delay) without skipping any index. Currently it skipping 4 index because of this line (i_value= 1:4:len). But I dont want to skip this index for my final result. How can I do that.
Thank you so much for your time and considerations.
data1=rand(1,1000)
data2=rand(1,1000)
data3=rand(1,1000)
len=200;
time=zeros(1,len)
trigger=3
for i_value= 1:4:len
delay1=data1(i_value)
delay2=data1(i_value+1)
delay_1=(delay1+delay2)/2
delay3=data2(i_value)
delay4=data2(i_value+1)
delay_2=(delay3+delay4)/2
RTT_1=data2(i_value+2)+data3(i_value)+data1(i_value+2)
final_delay(i_value)= abs(RTT_1-delay_1-delay_2)
end
  댓글 수: 5
madhan ravi
madhan ravi 2020년 7월 6일
Yet again you forgot to attach how the expected result should look like. Paste it as a text , screenshot is not useful.
Tania Islam
Tania Islam 2020년 7월 6일
Thank you so much for your time to consider this problem. I think I am close to my answer by @Matt J.

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

채택된 답변

Matt J
Matt J 2020년 7월 6일
편집: Matt J 2020년 7월 6일
I_values=1:4:len;
final_delay=nan(1,numel(I_values)); %PRE-ALLOCATE!!!!!!
for k=1:numel(I_values)
i_value=I_values(k);% Matt J inserted
delay1=data1(i_value)
delay2=data1(i_value+1)
delay_1=(delay1+delay2)/2
delay3=data2(i_value)
delay4=data2(i_value+1)
delay_2=(delay3+delay4)/2
RTT_1=data2(i_value+2)+data3(i_value)+data1(i_value+2)
final_delay(k)= abs(RTT_1-delay_1-delay_2) %Matt J edited
end
  댓글 수: 3
Matt J
Matt J 2020년 7월 6일
We are not deleting anything, just filling a smaller vector.
Tania Islam
Tania Islam 2020년 7월 7일
Thank you so much

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

추가 답변 (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