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!