Cinditional if for array

조회 수: 6 (최근 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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by