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 commentaires

maiaL
maiaL le 11 Août 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 le 12 Août 2020
@Leonardo Maia
I didn't receive any error, just want to ensure whether doing correctly or not?

Connectez-vous pour commenter.

 Réponse acceptée

hosein Javan
hosein Javan le 11 Août 2020

0 votes

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 commentaires

Rock Interpreter
Rock Interpreter le 12 Août 2020
I am sorry, but this is not working. According to this, I got:
idx_x and idx_y matrices that contains o(zeros). So there is no x_ext, y_ext and A_ext.
hosein Javan
hosein Javan le 12 Août 2020
Modifié(e) : hosein Javan le 12 Août 2020
yes, I have set an example in which X varys vertically and Y varies horizontally like yours. this example shows what you're looking for. in here we are extracting "1<x & x<5" and "2<y & y<6".
the only difference you have to make is that vectors "x" and "y" that here have been defined in first line of the code, you must create yourself by extracting one column and one row of Xmat and Ymat respectively.
x = 0:6
y = 0:7
[Y,X] = meshgrid(y,x)
A = X.^2 + Y.^2
idx_x = find(1<x & x<5) % linear index of x values
idx_y = find(2<y & y<6) % linear index of y values
A_ext = A(idx_x,idx_y) % extracted A corresponding to 1<x<5 and 2<y<6
results:
Y =
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
X =
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6
A =
0 1 4 9 16 25 36 49
1 2 5 10 17 26 37 50
4 5 8 13 20 29 40 53
9 10 13 18 25 34 45 58
16 17 20 25 32 41 52 65
25 26 29 34 41 50 61 74
36 37 40 45 52 61 72 85
idx_x =
3 4 5
idx_y =
4 5 6
A_ext =
13 20 29
18 25 34
25 32 41
you should be able to do the same for your matrix.
I think in your case it will be:
x = Xmat(:,1)
y = Ymat(1,:)
idx_x = find(349<x & x<589) % linear index of x values
idx_y = find(1381<y & y<1681) % linear index of y values
A_ext = A(idx_x,idx_y) % extracted A corresponding to 1<x<5 and 2<y<6
Rock Interpreter
Rock Interpreter le 12 Août 2020
Hi javan,
Thanks, but unfortunately, this is also not working. I am not understanding properly why
x = Xmat(:,1)
y = Ymat(1,:)
These creates vector only. I need the matrix. Basically all three matrices:xmat(longitude), ymat(latitude) and Amat(data) contain data throughout the world. I need to extract from some specific region which falls between xmat(349:589,:) and ymat(:,1381:1681). Now I need to extract Amat corresponding to these matrix ranges. Could you plz help now.
hosein Javan
hosein Javan le 12 Août 2020
hello again, Xmat and Ymat are matrices that have rows/columns being repeated. therefore we extract only one vector that has no data repeated in order to gain the range index of each coordinate. now that we have the indices we can extract data form A which is A_ext which is a matrix. you don't need "x" and "y". you only need A_ext. if you still have problem, upload your mat files so I can help you.
Rock Interpreter
Rock Interpreter le 12 Août 2020
Hello,
I am providing a link (https://figshare.com/account/articles/12794549), you please download three matrices:lat.mat (latitude), long.mat (longitude) and Amat.mat(data matrix). My zone of interest is Long: 50 to 100 (can be obatined from long.mat) and Lat: -15 to 25 (Can be obtained from lat.mat) and I need Amat values corresponding to these ranges of lat.mat and long.mat.
Thank you in cooperation.
Best regards
hosein Javan
hosein Javan le 12 Août 2020
please attach your file here.
Rock Interpreter
Rock Interpreter le 12 Août 2020
Hi, I tried, but it is showing that I can only attach upto 5MB. The total file is exceeding 5 MB after compressing as well. So I created a link for your easy accessibility.
hosein Javan
hosein Javan le 12 Août 2020
that site requires signup. attach them one by one in saparate comments.
Rock Interpreter
Rock Interpreter le 12 Août 2020
Hi, I could attach here long.mat and lat.mat; the data file Amat.mat is huge (16MB). So please try this link:
https://drive.google.com/file/d/13DLUdXvSR4maEiyee42ngIv1KeeAoVwO/view?usp=sharing for Amat.mat. I think this will be downloaded easily. Thanks for understanding the situation.
load('long.mat') % ydata
load('lat.mat') % xdata
load('Amat.mat')
latvec = latmat(:,1);
lonvec = lonmat(1,:);
idx_lat = find(-15<=latvec & latvec<=25);
idx_lon = find(50<lonvec & lonvec<100);
lat_ext = latmat(idx_lat,idx_lon);
lon_ext = lonmat(idx_lat,idx_lon);
A_ext = tij(idx_lat,idx_lon);
surf(lat_ext,lon_ext,A_ext,'EdgeColor','none')
xlabel('latitude');
ylabel('longitude');
zlabel('height')
the 3d result:
if you want to know each value corresponding to each coordinate points by one-click, use this figure:
I hope this is it.
Rock Interpreter
Rock Interpreter le 12 Août 2020
Hi Javan,
Yes, this is it. Thanks a ton for your support; appreciated it.
Best regards.
hosein Javan
hosein Javan le 12 Août 2020
your welcome. best wishes.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by