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!