How to count here?

4 ビュー (過去 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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by