Cinditional if for array

2 次查看(过去 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 中查找有关 Stress and Strain 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by