Azzera filtri
Azzera filtri

How can I make vectors within cell array consistent in length?

3 visualizzazioni (ultimi 30 giorni)
Please find attached file I want to make the all arrays in same length. I tried the comment below, doesn't work. I really appreciate in advance.
>> N = cellfun(@numel, X);
>> M = max(N);
>> OUT = cellfun(@(a) [a; nan(M - numel(a),1)],X,'uni',0);
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in @(a)[a;nan(M-numel(a),1)]
  1 Commento
Farshid Daryabor
Farshid Daryabor il 10 Mar 2020
I did it, just for the other user it can be usful.
[X_out, tf_x] = cellfun(@(x) padcat(x{:}), X, 'uni' , 0); % pads with NaNs
n = max(cellfun('size',X_out,1));
m = max(cellfun('size',X_out,2));
X_new = cell2mat(cellfun(@(x) [x, nan(size(x, 1), m-size(x, 2)); ...
nan(n-size(x, 1), m)], X, 'uni' , 0));

Accedi per commentare.

Risposte (0)


Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by