Reshaping and sizing a matrix

2 次查看(过去 30 天)
GCats
GCats 2021-6-2
编辑: GCats 2021-6-2
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!

回答(1 个)

KSSV
KSSV 2021-6-2
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 个评论
GCats
GCats 2021-6-2
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 2021-6-2
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by