Reshaping and sizing a matrix

2 views (last 30 days)
GCats
GCats on 2 Jun 2021
Edited: GCats on 2 Jun 2021
Hi all,
I have two matrices with dimensions A = [4096x2], B = [16384x2]. The first column shows frequency range in Hz, the second displacement.
I am interested in plotting the displacement at frequencies 150 to 500 where in matrix B, B(1:1) = 150 Hz and B(end:1) = 500. However, this is not the case for A, where A(1793,1) = 150 Hz and A(2864, 1) = 500 Hz. So pretty much the steps at which the measurements are taken are different. How can I reshape the matrices so to have the same dimensions and be able to element-wise divide them A./B?
Thank you!

Answers (1)

KSSV
KSSV on 2 Jun 2021
You can get the indices of your range and plot them.
idx = A(:,1) >= 150 & A(:,1) <= 500 ; % get your range of values
% plot
plot(A(idx,1),A(idx,2),'r')
hold on
plot(B(:,1),B(:,2),'b')
legend('A','B')
  2 Comments
GCats
GCats on 2 Jun 2021
Sorry, I think I explained the problem incorrectly. I have to divide A./B, hence I need them to be the same size.
KSSV
KSSV on 2 Jun 2021
It can be done too. Get them to same size using _interp1.
idx = A(:,1) >= 150 & A(:,1) <= 500 ; % get your range of values
A = A(idx,:) ;
A_new = interp1(A(:,1),A(:,2),B(:,1)) ;
A_new = [B(:,1) A_new] ;
Now A_new and B will have same dimensions.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!