Extracting matrix from mat file
조회 수: 3 (최근 30일)
이전 댓글 표시
I am working with 3 matrices of size 997*2160, which has been extracted from available mat file; First two matrices are x and y coordinates and last one data matrix:A. Now I would like to get the data matrix A corresponding to some specific part of x & y matrices. I have checked the range of x matrix that I require and it is (349:589,:), varying vertically and y matrix as (:,1381:1681), varying horizontally. I would require the data matrix A corresponding to these stated range.
I tried this:
x=xmat(349:589,:); % this generated 241*2160
y=ymat(:,1381:1681); % this generated 997*301
A=Amat(349:589,1381:1681); %this generated 241*301
Am I doing in right way? Please suggest if this is not correct. Your help will be very much appreciated.
Best regards,
Sumit G
댓글 수: 2
maiaL
2020년 8월 11일
If you tried that, what did you get as a result/error? At a first glance, it looks plausible to me.
채택된 답변
hosein Javan
2020년 8월 11일
I assume you have an "x" and a "y" rectangular grid point coordinates, and "A" contains "f(x,y)" data. in this case "x" is a row-vector repeated and "y" is a column vector repeated. now you're trying to extract coordinates ranging in these intervals: "349<x<589" and "1381<y<1681". if that is the case, you're code should look like:
idx_x = 349<x & x<589; % index of extracted x values
idx_y = 1381<y & y<1681; % index of extracted x values
x_ext = x(idx_x); % extracted x values
y_ext = x(idx_y); % extracted y values
A_ext = A(idx_x & idx_y) % extracted A values
what you were doing was to unnoticably replace data range by matrix index while they have to be calculated first as was shown.
댓글 수: 12
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

