how can I link 4 vectors based on their length? that is from the longest to the shortest

1 visualización (últimos 30 días)
I.e.
I have a=[5 5 5 5 5], b=[4 4 4 4], c=[3 3 3] and d=[2 2].
I want to concatenate out=[a b c d] without knowing, however, the length of a, b, c, d in each cycle.
Thank you.

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Abr. de 2018
values = {a, b, c, d};
lens = cellfun(@length, values);
[~, idx] = sort(lens, 'descend');
out = [values{idx}];

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by