How to return the smallest vector.
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
If I have N vectors of different length how would i isolate and return the vector of the smallest length? I dont care what the length is i just need which is the smallest one.
0 Kommentare
Akzeptierte Antwort
Matt J
am 17 Jan. 2020
Bearbeitet: Matt J
am 17 Jan. 2020
If you "have them" in cell array form, then you could do something like this:
>> vectors={[3 4 5],[1,2],[5 6 7 8]}
vectors =
1×3 cell array
{1×3 double} {1×2 double} {1×4 double}
>> [~,imin]=min(cellfun('length',vectors));
>> smallest=vectors{imin}
smallest =
1 2
3 Kommentare
Image Analyst
am 17 Jan. 2020
Well, what form were they in? Just separate variables? If so, you need to check their lengths one at a time.
Matt J
am 17 Jan. 2020
Or, you will have to load them into a cell array manually,
vectors={v1,v2,v3,...}
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!