Indexing of 1D arrays using 2D mapping information

27 ビュー (過去 30 日間)
LO
LO 2023 年 7 月 5 日
編集済み: Pranavkumar Mallela 2023 年 7 月 6 日
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! :)

採用された回答

chicken vector
chicken vector 2023 年 7 月 5 日
編集済み: chicken vector 2023 年 7 月 5 日
Have a look at this:
An adaption from griddata example:
% 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 件のコメント
LO
LO 2023 年 7 月 5 日
thank you ! :)
chicken vector
chicken vector 2023 年 7 月 5 日
My pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Pranavkumar Mallela
Pranavkumar Mallela 2023 年 7 月 5 日
編集済み: Pranavkumar Mallela 2023 年 7 月 6 日
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!

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by