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 Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by