Effacer les filtres
Effacer les filtres

I want to print only logical answer as shown in the example

1 vue (au cours des 30 derniers jours)
Manav Divekar
Manav Divekar le 29 Oct 2021
Commenté : Manav Divekar le 29 Oct 2021
function [out] = issortedvector(v)
x = sort(v);
if x == v
else
end
Example
issortedvector( [ -5 -3 10 20 25 29 ] )
ans = logical
1
or
>> issortedvector( [ 5 9 11 8 15 ] )
ans = logical
0

Réponse acceptée

Image Analyst
Image Analyst le 29 Oct 2021
Instead of
if x == v
else
end
try
out = all(x==v);
  3 commentaires
Image Analyst
Image Analyst le 29 Oct 2021
Modifié(e) : Image Analyst le 29 Oct 2021
if all(x == v)
out = true;
else
out = false;
end
Manav Divekar
Manav Divekar le 29 Oct 2021
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by