Cinditional if for array

4 views (last 30 days)
Saeid
Saeid on 17 Dec 2017
Commented: Saeid on 17 Dec 2017
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?

Accepted Answer

Birdman
Birdman on 17 Dec 2017
Change the if statement to
if numel(A)==0 && numel(B)==0
  1 Comment
Saeid
Saeid on 17 Dec 2017
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?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!