how to exclude a row based on a column value?

Dear All, I have a matrix called M, composed of 15 columns and 100000 rows, the third column supposed to be the month so the values in it must be from 1 to 12, how can i check if there is a value out of this range in this column, for example 13 or 0 or any thing not between 1 and 12? and after that delete the row that carries this error number?

 採用された回答

Star Strider
Star Strider 2018 年 2 月 13 日

0 投票

Try this:
M_edited = M((M(:,3)>=1) & (M(:,3)<=12), :);
It assigns only the rows in ‘M’ with months from 1 to 12 in ‘M_edited’. The others are not copied to it.

8 件のコメント

Roger Stafford
Roger Stafford 2018 年 2 月 13 日
@Mahmoud: Or if you fear some of the values are fractional, insert one more test:
M_edited = M((M(:,3)>=1) & (M(:,3)<=12) & (round(M(:,3))==M(:,3)), :);
Star Strider
Star Strider 2018 年 2 月 13 日
@Roger — Good point! I assumed they are defined as integers. If they are calculated, rounding them or using a tolerance value will be necessary.
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2018 年 2 月 13 日
thank you very much fr you help, this is amazing
Star Strider
Star Strider 2018 年 2 月 13 日
My pleasure.
Thank you for describing it as ‘amazing’, and please Accept it!
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2018 年 2 月 13 日
tell me please how to accept it
Star Strider
Star Strider 2018 年 2 月 13 日
Click on the blue Accept this answer button.
You may have to Unaccept another answer first. (The person will not lose points for an unaccepted answer. Points of an accepted answer are permanent, even if it is unaccepted later.)
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2018 年 2 月 13 日
I DID IT, THANKS
Star Strider
Star Strider 2018 年 2 月 13 日
As always, my pleasure!
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by