How to count here?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Chathu
el 22 de En. de 2015
Comentada: Chathu
el 22 de En. de 2015
Here is what i originally have:
'No.' 'Time'
'2011' '119.823011000'
'2012' '119.923206000'
'2013' '120.023454000'
'2014' '120.122663000'
'2015' '120.222851000'
'2016' '120.323050000'
'2017' '120.422283000'
'2018' '120.522470000'
'2019' '120.622677000'
'2020' '120.721896000'
'2021' '120.822124000'
'2022' '120.922356000'
'2023' '121.021516000'
'2024' '121.121760000'
'2025' '121.221989000'
In the Time column, i want to find the count till time < 121.000000000.
This is what i wrote:
No=floating(data{2}<121.000000000);
count=sum(~No)
But i got an error.
0 comentarios
Respuesta aceptada
Stephen23
el 22 de En. de 2015
Editada: Stephen23
el 22 de En. de 2015
You code is almost right, just the function floating is not known to MATLAB. It doesn't exist, unless you have written it yourself, and using it probably gives you an error ("Undefined function..."). But that is alright, the data class of data{2} values is not really very important anyway, as the < operator is defined for all numeric classes anyway, as well as logical and character arrays. Try this:
idx = data{2} < 121;
sum(~idx)
The documentation states the applicable data types for the lt operator. Tip: Have a look at the "Contents" panel on the left-hand side of the webpage. Explore it for a few minutes: this is a really great way to find related functions, and to explore what you can do with particular classes of data. Get comfortable with using these "Contents" and using MATLAB becomes a lots more fun and interesting!
Más respuestas (1)
David Sanchez
el 22 de En. de 2015
If you want to sum over the second column of your cell array untill the value of the cell is equal or greater to 121:
Since you have to start counting from your second row (first row is the variable name)
your_sum = 0; % initialize your summation
for k=2:size(your_cell,1)
if str2double(your_cell{k,2})>= 121
break
end
your_sum = str2double(your_cell{k,2}) + your_sum;
end
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!