Create grid of three sources and extract the values of each cell

11 visualizaciones (últimos 30 días)
Fran Andreu
Fran Andreu el 28 de Jul. de 2022
Respondida: Siraj el 29 de Sept. de 2023
Hi everyone, I am noob programming so I will really appreciate your all your advices :)
I load three different files to create a grid map and i get it. However, now I'm trying to create only one grid map with the values of three files and then i want to extract the value of each cell to create a line chart where X = number of cell and Y = values inside the cell
Could someone help me?
Thank you very much!
Fran
  2 comentarios
Jan
Jan el 28 de Jul. de 2022
What do you call "a grid map"? What is a "cell"? What is "number of a cell"?
It does not matter, where the data are coming from. Omit details like "loaded from a file", if they do not have a connection to the actual problem. But explain the actual details as exact as possible.
Fran Andreu
Fran Andreu el 28 de Jul. de 2022
Editada: dpb el 28 de Jul. de 2022
Thank you very much Jan for your quick response
I use this to create the cell chart and determine the size I want the cells to be. Then according to the coordinates cells are filled with values or if there is not a value is not filled.
I have it for three sources of data. Now I'm trying to join all the data in the same cell chart. Then i want extract the number cells and value that there is inside the cell. I want to create a line chart to study the values that I have in each cells and how it evolve.
¿How i can to join the three values in the same cell chart and then extract the number of cell and the values that there are inside?
Hope this explains what I am doing:
XEastA = dataA(:,2); % X_East coordinate A
YNorthA = dataA(:,3); % North coordinate A
cA = 3
maxNorthA = max(max(YNorthA));
maxEastA = max(max(XEastA));
minNorthA = min(min(YNorthA));
minEastA = min(min(XEastA));
% Grid resolution A
hA = abs(maxEastA - minEastA)/cA;
vA = abs(maxNorthA - minNorthA)/cA;
HA = ceil(hA); % setting values up
VA = ceil(vA); % setting values up
Resol = HA*VA;
% Grid creation A
gridErrordosiA = -10*ones(VA, HA);
repeA = 0;
% Grid refelling A
for k = 1:np
xA = ceil(abs(XEastA(k)/cA)- minEastA/cA);
yA = ceil(abs(YNorthA(k)/cA) - minNorthA/cA);
if xA < 1
xA =1;
end
if xA > HA
xA = HA;
end
if yA < 1
yA = 1;
end
if yA > VA
yA = VA;
end
if gridErrordosiA(yA, xA) ~= -10 % If there is a value
gridErrordosiA(yA, xA) = 0.5 * (ErrordosiA(k) + gridErrordosiA(yA, xA));
repeA = repeA + 1;
else
gridErrordosiA(yA, xA) = ErrordosiA(k);
end
end
% Representación grid del error absoluto en la dosis en mapa Tipo A
figure1 = figure('Color',[1 1 1]);
surf(gridErrordosiA);
view (0,90);
axis equal;
axis ([0 HA+1 0 VA+1]);
xlabel('','fontweight','bold', 'Fontsize',12);
ylabel('','fontweight','bold', 'Fontsize', 12);
title ('','bold','Fontsize', 20);
set(gca,'fontweight','bold', 'fontsize', 12);
map = [1 1 1; 1 0 0; 0.5 0 0;0.7 0.1 0.1;1 0.6 0.6; 0 1 0;
0.7 0.8 0.4;0.96078431372549 0.937254901960784 0.749019607843137;
0.8 0.8 0.9;0.650980392156863 0.872549019607843 0.966666666666667;
0.301960784313726 0.745098039215686 0.933333333333333];

Iniciar sesión para comentar.

Respuestas (1)

Siraj
Siraj el 29 de Sept. de 2023
Hi!
I understand that you have three separate files, and from each file, you have created a grid map. Now, you want to merge all three grid maps into a single grid map. However, you haven't specified how the combined grid should be organized. For instance, it is unclear whether a new row or column should be added when transitioning from one file to the next, or how the cells should be numbered when merging the grids.
To combine the three separate grid maps into a single grid map in MATLAB, you can use the "cat" function. The specific approach will depend on your requirements and how you want the grids to be merged. The "cat" function allows you to concatenate arrays along a specified dimension. Refer to the following link for more details on how to use the "cat" function.
For additional information on various methods of concatenating and expanding matrices in MATLAB, refer to the following link.
To provide a clearer understanding, I have included a short example code snippet below:
% Define the dimensions of the grids
rows = 2;
cols = 2;
% Generate the first random grid
grid1 = rand(rows, cols);
% Generate the second random grid
grid2 = rand(rows, cols);
% Generate the third random grid
grid3 = rand(rows, cols);
% Concatenate the grids horizontally
final_grid_horizontal_using_cat = cat(2,grid1 ,grid2, grid3)
final_grid_horizontal_using_cat = 2×6
0.0513 0.7384 0.2132 0.9708 0.2810 0.2812 0.3941 0.5157 0.3872 0.7768 0.2848 0.4046
final_grid_horizontal_using_array_concatenation = [grid1 ,grid2, grid3]
final_grid_horizontal_using_array_concatenation = 2×6
0.0513 0.7384 0.2132 0.9708 0.2810 0.2812 0.3941 0.5157 0.3872 0.7768 0.2848 0.4046
% Concatenate the grids vertically
final_grid_vertical_using_cat = cat(1,grid1 ,grid2, grid3)
final_grid_vertical_using_cat = 6×2
0.0513 0.7384 0.3941 0.5157 0.2132 0.9708 0.3872 0.7768 0.2810 0.2812 0.2848 0.4046
final_grid_vertical_using_array_concatenation = [grid1; grid2; grid3]
final_grid_vertical_using_array_concatenation = 6×2
0.0513 0.7384 0.3941 0.5157 0.2132 0.9708 0.3872 0.7768 0.2810 0.2812 0.2848 0.4046
Hope this helps.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by