Effacer les filtres
Effacer les filtres

Extract matrix from matrix

2 vues (au cours des 30 derniers jours)
Chihiro Omori
Chihiro Omori le 12 Avr 2019
Commenté : Bob Thompson le 12 Avr 2019
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?

Réponses (1)

Bob Thompson
Bob Thompson le 12 Avr 2019
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 commentaires
Chihiro Omori
Chihiro Omori le 12 Avr 2019
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 le 12 Avr 2019
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by