Conditional if statement solution

조회 수: 4 (최근 30일)
Tino
Tino 2019년 8월 15일
답변: Rik 2019년 8월 15일
I will greatly appreciate it if any one assist me in solving this problem in Matlab code
For instance I have a list of values = 3 4 6 3 4 5 10 7 4 5 3 4
The code contains two if statement
if values > 9
in this case it is in position 7 : display the positions in values that meet condition ( if value > 9) in the example above it is the 7th position (10)
then calculate the 5 numbers before and after including position 7th (10) itself an example
average = (4 + 5 + 10 + 7 + 4 )/5 = 6
if (average > 9)
true changes showing ( 7th position = 10 )
else
false changes (7th position = 10 )
end if statement
end if statement
The answer is false change detection
I will like to be assisted with the code as I want to apply these to large data
Thanks in advance
  댓글 수: 4
Geoff Hayes
Geoff Hayes 2019년 8월 15일
So you will want to find all elements that are greater than nine and then apply the logic to each one presumably storing the result of each in an array.
Tino
Tino 2019년 8월 15일
Yes Geoff with a discription if they are true changes or false changes

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

채택된 답변

Rik
Rik 2019년 8월 15일
In Matlab calculating parameters for the entire array at once is almost always faster than a loop. My code below uses the find function (as Geoff hinted at), and it uses a convolution to find the moving average for each position. You should check if this matches your requirements for the edge cases. If you want to display the results in a different way, you should be able to add code that suits your need.
values =[3 4 6 3 4 5 10 7 4 5 3 4];
window=ones(1,5)/5;
avg=conv(values,window,'same');
true_changes=find( values>9 & avg>9 );
false_changes=find( values>9 & avg<=9 );

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by