How to get the exact lat lon position of nc file data

2 visualizaciones (últimos 30 días)
Karthik M
Karthik M el 7 de Oct. de 2021
Respondida: ag el 29 de En. de 2025
Hi Folks
Thanks in advance
I could get the indexed position of the rows and columns of max / index value data with the below code
maxval=max(data(:));
[xmax,ymax]=find(data==maxval);
[ii,jj]=find(data >= 0 & data < 2);
but I need only the exact x and y location coordinates
I have classify the pixel values range according to my requirement as below
idx = data >= 0 & data< 2 ;
pix1 = data(idx);
idx = data >= 2 & data < 4 ;
pix2 = data(idx) ;
idx = iwant >= 4 & iwant < 6 ;
pix3 = data(idx) ;
idx = data >= 6 & data < 8 ;
pix4 = data(idx) ;
idx = data >= 8 & data < 10;
pix5 = data(idx);
idx = data >= 10 & data < 15 ;
pix6 = data(idx) ;
idx = data >= 15 & data < 20 ;
pix7 = data(idx) ;
idx= data >= 20 & data < 95;
pix8 = data(idx);
please find the atached data and lat, lon position
Kindly help

Respuestas (1)

ag
ag el 29 de En. de 2025
To extract the exact x and y coordinates of pixels that fall within specific value ranges in a matrix, you can modify your approach slightly. Instead of just extracting the pixel values, you need to also find their corresponding indices.
Below is a modified version of your code with explainatory comments:
% Example data matrix
data = randi([0, 100], 10, 10); % Replace with your actual data
% Initialize cell arrays to store coordinates
coordinates = cell(8, 1);
% Define ranges and find indices for each range
ranges = [0 2; 2 4; 4 6; 6 8; 8 10; 10 15; 15 20; 20 95];
for k = 1:size(ranges, 1)
% Get logical index for current range
idx = data >= ranges(k, 1) & data < ranges(k, 2);
% Find coordinates of pixels in this range
[x, y] = find(idx);
% Store coordinates in the cell array
coordinates{k} = [x, y];
end
% Display coordinates for each range
for k = 1:size(ranges, 1)
fprintf('Coordinates for range [%d, %d):\n', ranges(k, 1), ranges(k, 2));
disp(coordinates{k});
end
Coordinates for range [0, 2): Coordinates for range [2, 4):
4 6 1 7 5 8 7 8
Coordinates for range [4, 6):
2 3
Coordinates for range [6, 8):
8 7
Coordinates for range [8, 10): Coordinates for range [10, 15):
5 4 9 4 10 5 2 6 8 6 9 6 6 7
Coordinates for range [15, 20):
8 1 1 5 4 5 3 8 3 9 5 9 6 9 9 9 2 10 8 10
Coordinates for range [20, 95):
1 1 3 1 4 1 5 1 6 1 7 1 9 1 10 1 1 2 2 2 5 2 6 2 7 2 8 2 9 2 10 2 1 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 1 4 2 4 4 4 6 4 7 4 8 4 10 4 2 5 3 5 5 5 6 5 7 5 8 5 9 5 1 6 3 6 5 6 6 6 7 6 10 6 2 7 3 7 4 7 5 7 7 7 10 7 2 8 4 8 6 8 8 8 9 8 1 9 2 9 4 9 7 9 8 9 10 9 1 10 3 10 4 10 5 10 6 10 7 10 9 10 10 10
Hope this helps!

Categorías

Más información sobre Simulink en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by