combine Latitude and longitude country data from multiple arrays into one array

5 views (last 30 days)
I have an array (MYD_countries) of size 249*64800 in which the first dimension represents different countries in the world and the second dimension represents global data grid cells of 1-degree data (180*360 = 64800). Each country data has data values within the country grid points and NaN elsewhere. I want to combine the data of all countries together and reduce its dimension to 1*64800 so that I can plot it at one call using geoshow. I have tried it using a loop as below but it is only storing the last country data, not all country data. Could anybody help please?
for i = 1:249;
for j = 1:64800;
if(MYD_countries(i, j) ~= NaN);
MYD_all_countries_plot (1, j) = MYD_countries (i, j);
else;
end;
end;
end;

Accepted Answer

Sagar Parajuli
Sagar Parajuli on 4 Aug 2021
I solved this problem with a simple technique using 'max' function.
data_2d = max(MYD_countries, [], 1); %taking maximum along the first dimension retains the data for each country since values are NaN elsewhere.

More Answers (1)

KSSV
KSSV on 22 Jul 2021
Let A be your data of size 249*64800
[m,n] = size(A) ;
iwant = zeros(180,360,m) ;
for i = 1:m
iwant(:,:,i) = reshape(A(i,:),180,360) ;
end
Now iwant variable is a 3D matrix of size 180*360*249; each 2D matrix represents a country. You can plot it now.
  3 Comments
Sagar Parajuli
Sagar Parajuli on 22 Jul 2021
I need to plot all the data together at once, not only one country. I can't use a loop in geoshow, that is my problem. The real problem I want to solve creatively is to reduce the data dimension from 249*64800 to 1*64800 which should be possible because the countries are unique in each country layer. I basically want to extract only those grid cells with data (all other grid cells have NaN) in each country and put it in a 2-d array so that data from all the countries is there in a single 2-d array.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!