issue when using 'for' and 'elseif'
Afficher commentaires plus anciens
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 commentaires
Geoff Hayes
le 24 Avr 2020
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
le 25 Avr 2020
Geoff Hayes
le 25 Avr 2020
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
le 25 Avr 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!