# Indexing of 1D arrays using 2D mapping information

42 visualizaciones (últimos 30 días)
LO el 5 de Jul. de 2023
Editada: Pranavkumar Mallela el 6 de Jul. de 2023
I have 3 one-dimensional arrays, 2 of them contain XY coordinates while the third (called 'E') contains some other non spatial parameter (i.e. electric field intensity).
I would like to create a heatmap of the values of E, based on the corresponding XY positions. Each vector has the same numerosity (around 3000 points). However, the XY coordinates are not regularly spaced (this is because they are extracted from a moving probe, whch movement was then tracked).
So, what I did so far was:
1) create an empty matrix to fill, sized as the area covered by the probe
% determine field size
size_X = abs(max(xd)-min(xd));
size_Y = abs(max(yd)-min(yd));
% create blank map
map = zeros(size_Y,size_X);
2) try to fill the 2D array indexing the closest points to each of the "standardized" array slots using a loop
for j = 1:30 & row index
for i = 1: 20 % column index
[~, x_index]=min(abs(xd-i));
[~, y_index]=min(abs(yd-j));
map(j,i) = E(find the index of the E array corresponding to xd(i) and yd(j)???);
end
end
I thought to use something like sub2ind to find the correct index.. but the problem is that E is not a 2D map ...is just a straight vector such X and Y. I also tried to map E on X and Y using the scatter function but somehow the result is not what I would like to have.
scatter(xd,yd,[],E,'filled')
should I interpolate the values the spatial vectors and then use the params to transform E ? or something like that... ? I am not sure
thank you for any tip! :)
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

chicken vector el 5 de Jul. de 2023
Editada: chicken vector el 5 de Jul. de 2023
Have a look at this:
% Create fake data (X,Y,E):
nPoints = 300;
x = -2.5 + 5*rand(nPoints,1);
y = -2.5 + 5*rand(nPoints,1);
v = x.*exp(-x.^2-y.^2);
% Interpolate the scattered data to obtain the regular grid:
[xq,yq] = meshgrid(min(x):.1:max(x), min(y):.1:max(y));
vq = griddata(x,y,v,xq,yq);
figure;
tiledlayout(1,2);
nexttile
color = (v-min(v))/(max(v)-min(v));
scatter(x,y,50,color,'filled')
nexttile
surf(xq,yq,vq,'EdgeColor','None')
xlim([min(x) max(x)])
ylim([min(y) max(y)])
view([0,0,1])
##### 2 comentariosMostrar NingunoOcultar Ninguno
LO el 5 de Jul. de 2023
thank you ! :)
chicken vector el 5 de Jul. de 2023
My pleasure!

Iniciar sesión para comentar.

### Más respuestas (1)

Pranavkumar Mallela el 5 de Jul. de 2023
Editada: Pranavkumar Mallela el 6 de Jul. de 2023
Hi,
As per my understanding, you want to make a heat map for a given set of (X,Y) coordinates.
In your code, you are iterating over the 'standardized slots' and trying to map the E value to the corresponding slot. Instead, if you iterate over the data points, you could map the E value based on the approx index of each data point. This can be done using the following formula:
newValue = newMin + ((newMax - newMin) / (oldMax - oldMin))*(value - oldMin)
% determine field size
size_X = abs(max(xd)-min(xd));
size_Y = abs(max(yd)-min(yd));
% create blank map
map = zeros(size_Y,size_X);
% Iterate over data points
for i = 1:length(xd)
x_index = x_mappedIndex(xd(i)); % use the formula above to define this function
y_index = y_mappedIndex(yd(i)); % use the formula above to define this function
map(x_index, y_index) = E(i);
end
This way, mapping the "E" value would be straightforward. I hope this helps! Thanks!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by