I want to print only logical answer as shown in the example
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Manav Divekar
il 29 Ott 2021
Commentato: Manav Divekar
il 29 Ott 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
0 Commenti
Risposta accettata
Image Analyst
il 29 Ott 2021
Instead of
if x == v
else
end
try
out = all(x==v);
3 Commenti
Image Analyst
il 29 Ott 2021
Modificato: Image Analyst
il 29 Ott 2021
if all(x == v)
out = true;
else
out = false;
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!