Cinditional if for array

9 ビュー (過去 30 日間)
Saeid
Saeid 2017 年 12 月 17 日
コメント済み: Saeid 2017 年 12 月 17 日
I want to activate some function on two matrices (e.g. multiply them) depending on the condition that two matrices A & B are not empty. I tried the statement:
if A~=[] & B~=[]
C=A.*B
end
but I receive the error message:
Error using ~=
Matrix dimensions must agree.
How can I correct this?

採用された回答

Birdman
Birdman 2017 年 12 月 17 日
Change the if statement to
if numel(A)==0 && numel(B)==0
  1 件のコメント
Saeid
Saeid 2017 年 12 月 17 日
Thanks, but I guess since I did not ask my question completely it seems like that your answer can help only partially. The original reason I ask the question is that I read the contents of an exel file that contains both text and numerical data, e.g.
Normal Stress 100 300 500
Shear Stress 50 70 30
Deformation 200 900 500
Tempereature 20 45 13
I usually use _ strcmpi_ to find the desired text and then assign values that are in the next columns. However, sometimes the excel file does no contain that text but I do not know beforehand, hence the original question. In this case I want MATLAB to figure if there is such an array (e.g. Deformation) and only if it exists then execute a certain command. How can I do that?

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by