MATLAB Answers

0

Make two matrices of same length reducing the size of largest matrix

Asked by Poulomi Ganguli on 15 Aug 2017
Latest activity Edited by José-Luis
on 16 Aug 2017
Hello, I have two matrix, A = [318x1] and B = [313x1]. In order to compare between two, I need to make size of A same as that of B, by reducing the size of A. Any help?

  2 Comments

And how would the "reducing" work?

Sign in to comment.

Tags

2 Answers

Answer by Ryan Klots on 15 Aug 2017
Edited by Ryan Klots on 15 Aug 2017
 Accepted Answer

You could try something like
% Find out the length of the shorter matrix
minLength = min(length(A), length(B));
% Removes any extra elements from the longer matrix
A = A(1:minLength);
B = B(1:minLength);

  0 Comments

Sign in to comment.


Answer by José-Luis
on 15 Aug 2017
Edited by José-Luis
on 16 Aug 2017

result = {A,B}
minDim = min(cellfun(@numel,result));
result = cellfun(@(x) {x(1:minDim)}, result);

  0 Comments

Sign in to comment.