i want to execute if else statement using size of array or matrix?

For example:
if size(A)=4*3 % 4*3 is row*column
fprintf ("something")
else
fprintf ("nothing")
then what is the correct way to execute such problem?

 Réponse acceptée

Matt J
Matt J le 11 Fév 2018
Modifié(e) : Matt J le 11 Fév 2018
if isequal(size(A),[4,3])
fprintf ("something")
else
fprintf ("nothing")
end

Plus de réponses (1)

Matt J
Matt J le 11 Fév 2018
Modifié(e) : Matt J le 11 Fév 2018
Using the attached utility,
if equalldims(size(A),[4,3])
fprintf ("something")
else
fprintf ("nothing")
end
This is a little more bulletproof, dealing with things like trailing ones that shouldn't affect the comparison,
>> equaldims(size(rand(4,3)), [4,3,1,1,1,1,1,1])
ans =
logical
1

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by