Extracting matrix from mat file
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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.
Rock Interpreter
2020년 8월 12일
@Leonardo Maia
I didn't receive any error, just want to ensure whether doing correctly or not?
채택된 답변
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
Rock Interpreter
2020년 8월 12일
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
2020년 8월 12일
편집: hosein Javan
2020년 8월 12일
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
2020년 8월 12일
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
2020년 8월 12일
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
2020년 8월 12일
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
2020년 8월 12일
please attach your file here.
Rock Interpreter
2020년 8월 12일
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
2020년 8월 12일
that site requires signup. attach them one by one in saparate comments.
Rock Interpreter
2020년 8월 12일
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
2020년 8월 12일
Hi Javan,
Yes, this is it. Thanks a ton for your support; appreciated it.
Best regards.
hosein Javan
2020년 8월 12일
your welcome. best wishes.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Earth and Planetary Science에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
