필터 지우기
필터 지우기

Extract matrix from matrix

조회 수: 2 (최근 30일)
Chihiro Omori
Chihiro Omori 2019년 4월 12일
댓글: Bob Thompson 2019년 4월 12일
The datasets I am using are
  • latmat.mat (172*172)....latitude data
  • lonmat.mat(172*172)...longitude data
  • CH4.mat (172*172)...air pollutant emission data[mol/sec]
I would like to make smaller matrix within those ranges below because the original datasets are too large to deal with.
  1. 70W<Longitude<75W
  2. 40N<Latitude<43N
Three datasets(lat.mat, lon.mat, CH4.mat) have to meet the conditions above.
How can I extract the datasets and make new matrix?

답변 (1개)

Bob Thompson
Bob Thompson 2019년 4월 12일
In general you should be able to do this with logic indexing fairly easily. I'm a little confused though how or why you have a 2D matrix of longitude and of latitude. Are each row or column duplicates (such that together they make a field of all lat and long combinations?
For the sake of the example I'm going to assume that latitudes only change with each row, and longitude only change with each column. Also assuming that north is postive, and west is negative. It is possible to do this with strings (for number and direction combination), but it seems unnecessarily complicated.
lats = latmat(latmat(:,1)>= 40 & latmat(:,1)<=43,lonmat(1,:)<=-70 & lonmat(1,:)>=-73);
lons = lonmat(latmat(:,1)>= 40 & latmat(:,1)<=43,lonmat(1,:)<=-70 & lonmat(1,:)>=-73);
CH4s = CH4(latmat(:,1)>= 40 & latmat(:,1)<=43,lonmat(1,:)<=-70 & lonmat(1,:)>=-73);
  댓글 수: 2
Chihiro Omori
Chihiro Omori 2019년 4월 12일
I ran the code but all of them (lats, lons, CH4s) are empty.
lats = []
lons = []
CH4s = []
Is it supposed to be matrix?
Bob Thompson
Bob Thompson 2019년 4월 12일
Most likely it will need some adapting. I don't have the ability to download your files, sorry, so I can't personalize it very much for you. Do you understand what the code I posted is supposed to be doing? I would be happy to help you understand if not.
Basically, I expect that they are all empty because it is not finding values or ranges which match the conditions I set, so you will need to adjust the conditions to make them work.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by