issue when using 'for' and 'elseif'
이전 댓글 표시
hi, im very new to matlab and i'm trying to write code which sorts through a table and finds values which adhere to the conditions ie waveheight is 2<x<4 or 4<x<6 etc.
the code is below, my issue is whenever i try write the count-
"for T2 =1:size(T2)"
it just gives me an output of 1, I have worked out the 'elseif' segment of this code but it wont work unless I get this for loop to work. I've tried loads of different variations of code but i just cant seem to get it to work
I am also on mac
thanks, ben.
댓글 수: 4
Geoff Hayes
2020년 4월 24일
Ben - how does the attached code refer to your question? I don't see any for loops or if/elseif segments. As for the code
for T2 =1:size(T2)
what is T2? Presumably it is an array...in which case you don't want to re-use this variable as the loop iterator. Also, are you iterating over the rows or columns (or some other dimension) of T2? Calling size returns an array of the dimensions sizes. So the size of a 2x3 array would be [2 3]. Your code could look like
for k = 1:length(T2)
where we assume that T2 is a 1-D array. If you want to iterator over the number of rows, you would do
for k = 1:size(T2,1)
or columns
for k = 1:length(T2,2)
etc.
Ben Murphy
2020년 4월 25일
Geoff Hayes
2020년 4월 25일
Ok - I recommend reposting the code for this problem, where you include your for loop and if/else checks. You may not even need a for loop..
Ben Murphy
2020년 4월 25일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 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!