Effacer les filtres
Effacer les filtres

Error in length of matrix

3 vues (au cours des 30 derniers jours)
Yasmin Tamimi
Yasmin Tamimi le 23 Juil 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!!

Réponse acceptée

Jan
Jan le 23 Juil 2012
Modifié(e) : Jan le 23 Juil 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

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by