Reshaping and sizing a matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
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
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 Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!