Azzera filtri
Azzera filtri

Error in length of matrix

3 visualizzazioni (ultimi 30 giorni)
Yasmin Tamimi
Yasmin Tamimi il 23 Lug 2012
Hey Everyone,
I have 2 txt file the first one is A with size (70x15) and the other one B with size (12x15). I want to make them both of the same size without cutting data, so I padded the other one with nans.
B = importdata('definite.txt'); %% when I read the matrix and when I type whos I get the size of (12x15) BUT when I write length(B) I get 15!!!
pad= nan((length(A) - length(B)),15); Data_definite = [A;pad];
Som I couldn't figure what is wrong!! I tried doing so with other txt files and it worked fine except with this one!!

Risposta accettata

Jan
Jan il 23 Lug 2012
Modificato: Jan il 23 Lug 2012
I do not understand, what the problem is. I guess, that you expect length() to reply the length of the first dimension. But as doc length explains, it replies the length of the longest dimension or 0, if the array is empty.
X = rand(12, 15);
length(X)
size(X)
size(X, 1) % <== I think you want this

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by