Add row to an empty array if a condition is fulfilled

5 ビュー (過去 30 日間)
Mariel Cristo
Mariel Cristo 2021 年 4 月 21 日
編集済み: Mariel Cristo 2021 年 4 月 22 日
Hi everyone,
I have a 5 x 3 array and I have to make a code that checks row by row if the third column fulfills a condition. (In this case, the third column should be equal to the letter "A").
When there's an "A" in the third column, I have to take all that row and place it in a new array and this new array should have all the rows that fulfill the condition.
Edit:
And if I were to do it with a database that I have on Excel, how do I do it?
The column that has the condition that I need is the number 74, that's called "Usar". I tried it with the logical indexing but it showed me nothing.

採用された回答

James Tursa
James Tursa 2021 年 4 月 21 日
編集済み: James Tursa 2021 年 4 月 21 日
No need for an explicit loop. Just use logical indexing:
result = m(strcmp(m(:,3),'A'),:);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by