Error in length of matrix

6 views (last 30 days)
Yasmin Tamimi
Yasmin Tamimi on 23 Jul 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!!

Accepted Answer

Jan
Jan on 23 Jul 2012
Edited: Jan on 23 Jul 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

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!