フィルターのクリア

How to check multiple values of one variable in if statement

17 ビュー (過去 30 日間)
Faranak Sharifi-Babaki
Faranak Sharifi-Babaki 2019 年 2 月 1 日
Hi,
I am writing a piece of code that checks for zero columns in a matrix. It stores all zero columns it finds in the value col. I later want to check the values for variable col in different if statements. However, when I write it like this it runs into errors:
%find all columns where there is zero vector
col = find(all(R == 0))
if col == [1 2 3]
//does something
end
This code works fine when col has 3 values, but when it has 4 values like col = 1 2 3 4, it gives the error: Matrix dimensions must agree. Is there another way I could check for multiple col values? Thanks!!
  1 件のコメント
Kevin Phung
Kevin Phung 2019 年 2 月 1 日
編集済み: Kevin Phung 2019 年 2 月 1 日
you have to be more specific, what is the 'something' that you are doing?

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

採用された回答

Bob Thompson
Bob Thompson 2019 年 2 月 1 日
編集済み: Bob Thompson 2019 年 2 月 1 日
You should just be able to index your if condition.
if col(1:3) == [1 2 3]
// do something
end

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by