필터 지우기
필터 지우기

Reshaping and sizing a matrix

조회 수: 1 (최근 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에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by