How to count here?

조회 수: 1 (최근 30일)
Chathu
Chathu 2015년 1월 22일
댓글: Chathu 2015년 1월 22일
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.

채택된 답변

Stephen23
Stephen23 2015년 1월 22일
편집: Stephen23 2015년 1월 22일
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!
  댓글 수: 1
Chathu
Chathu 2015년 1월 22일
@ Stephen- it works. Thank you so much.
In addition, thanks alot for the extra piece of information.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

David Sanchez
David Sanchez 2015년 1월 22일
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
  댓글 수: 1
Chathu
Chathu 2015년 1월 22일
@ David- thanks alot for your response. Can you kindly tell me what does "your_cell" refers in your For loop? i guess it's the time column,correct?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by