combine different size vectors into one matrix
Mostrar comentarios más antiguos
I need to combine sets of data I have together into one matrix, but they have different dimensions.
this is a simplified example:
e=[2 3 4 5];
>> ee=[4 7 7];
>> eee=[8 8 7 4 2 5];
>> p=[e; ee; eee];
I want to fill nan to make them even, but I don't know how.
I want each vector to be in a raw, so I get something like that
p=[2 3 4 5 NaN NaN;
4 7 7 NaN NaN NaN;
8 8 7 4 2 5];
then I want to get the mean for each column data
any suggestions please.
Respuesta aceptada
Más respuestas (1)
I will assume you have the vectors in a cell array
C={[2 3 4 5];
[4 7 7];
[8 8 7 4 2 5]}
Then, you can simply do,
z=max(cellfun('length',C));
p=cell2mat( cellfun(@(x)[x,nan(1,z-numel(x) )] ,C,'uni',0))
1 comentario
Suzuki
el 17 de Sept. de 2021
Categorías
Más información sobre NaNs en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!