Loop reading data into equation, store into array
조회 수: 7 (최근 30일)
이전 댓글 표시
I have imported in data that contains 5 columns and I would like to create a loop that will identify when the 5th column increases and decreases >2 points and will store the value of the 3rd column into A1 and the value of the 5th column into B1, then I want the loop to continue until the 5th column once again increases or decreases >2 points and repeat the process for A2 and B2 and then use those variables to calculate or C=abs(A1*B2+A2*B1). I want the loop to do this till the end of the imported data file and then store all the C's into an array.
Thank You
댓글 수: 2
dpb
2019년 6월 7일
More than likely you don't need a loop--but you do need to precisely define what is meant by "when the 5th column increases and decreases >2 points". More than likely giving a short example dataset with inputs and expected outputs is the easiest way to explain this--and attaching a sample input data file saves folks from trying to recreate something from scratch.
답변 (1개)
dpb
2019년 6월 10일
data=importdata('yourfile.txt');
ix2=[false; abs(diff(ata(:,5)>=2))];
newdata=data(ix2,[3 5]);
댓글 수: 0
참고 항목
카테고리
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!