X,Y cordinates in a Matrix

2 ビュー (過去 30 日間)
Alonso Canabal
Alonso Canabal 2022 年 2 月 18 日
回答済み: Image Analyst 2022 年 2 月 18 日
Hi, In an effort to create a heatmap y want to convert a list of X,Y coordinates to a 2D matrix. If a point x,y belongs to a point in the matrix a 1 should appear, is more than one point belong into a single matrix coordinate, the number of the points should appear.
A handmade example
A =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
>> XY
XY =
1 3 5 2 3
1 4 2 2 4
>> B
B =
1 0 0 0 0
0 1 0 0 1
0 0 0 0 0
0 0 2 0 0
0 1 0 0 0
This is to create a high resolution nice heatmaps with a ton of numbers. Thank you very much

採用された回答

AndresVar
AndresVar 2022 年 2 月 18 日
Loop through your points like this, although I see XY is probably very long!
A=zeros(3,3);
disp(A)
0 0 0 0 0 0 0 0 0
B=[1 1 1;
1 3 3];
for ii = 1:size(B,2)
A(B(1,ii),B(2,ii))=A(B(1,ii),B(2,ii))+1;
end
disp(A)
1 0 2 0 0 0 0 0 0

その他の回答 (2 件)

Kevin Holly
Kevin Holly 2022 年 2 月 18 日
編集済み: Kevin Holly 2022 年 2 月 18 日
A = [0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0];
XY = [1 3 5 2 3
1 4 2 2 4];
B=A;
for i = 1:length(XY)
A(XY(2,i),XY(1,i))= 1;
B = B + A;
A=zeros(5);
end
B
B = 5×5
1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0
imagesc(B)

Image Analyst
Image Analyst 2022 年 2 月 18 日
If you need to interpolate points everywhere, see scatteredInterpolant. Demo is attached.

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by