Filter löschen
Filter löschen

How to make each matrix in a cell of equal size by adding NaN?

2 Ansichten (letzte 30 Tage)
Antonio
Antonio am 19 Jan. 2018
Kommentiert: Antonio am 19 Jan. 2018
How may I make each matrix in a cell of equal size by adding NaN? My data is a 1000x1 cell containing 'nx2' sized matrices and looks like this:
A =
[8x2 double]
[6x2 double]
[9x2 double]
[6x2 double]
[7x2 double]
...

Akzeptierte Antwort

Birdman
Birdman am 19 Jan. 2018
An approach:
A={rand(8,2);rand(6,2);rand(9,2);rand(6,2);rand(7,2)};
sizesRow=cellfun(@(x) size(x,1),A);
addition=max(sizesRow)-sizesRow;
for i=1:size(A,1)
A{i}(sizesRow(i)+1:sizesRow(i)+addition(i),:)=NaN;
end
  3 Kommentare
Antonio
Antonio am 19 Jan. 2018
Thank you guys. @Birdman @Jan Simon

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by