Extracting matrix from mat file

11 views (last 30 days)
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 Comments
maiaL
maiaL on 11 Aug 2020
If you tried that, what did you get as a result/error? At a first glance, it looks plausible to me.
Rock Interpreter
Rock Interpreter on 12 Aug 2020
@Leonardo Maia
I didn't receive any error, just want to ensure whether doing correctly or not?

Sign in to comment.

Accepted Answer

hosein Javan
hosein Javan on 11 Aug 2020
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 Comments
Rock Interpreter
Rock Interpreter on 12 Aug 2020
Hi Javan,
Yes, this is it. Thanks a ton for your support; appreciated it.
Best regards.
hosein Javan
hosein Javan on 12 Aug 2020
your welcome. best wishes.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!