2d scan plot in matlab

7 次查看(过去 30 天)
Hi,
I want to scan over 2 quantities lets say x and y. For every value of x, I scan over a range of y and record value z for every point. So I have an (x,y) grid and have z which is an x by y matrix. How would I do a 2D plot of over such quantities. Many thanks for any lead.

采纳的回答

Star Strider
Star Strider 2021-1-29
What your Question lacks in clarity it makes up for in obfuscation.
See if my Answer to Create array from table with observations with two codes will do what you want.
  2 个评论
Sumera Yamin
Sumera Yamin 2021-1-29
编辑:Sumera Yamin 2021-1-29
Many thanks for your reply. i do not want to creat an array, my problem is with plotting. Lets say i already have an array how would i plot a quantity z (which is a x by y matrix) over an (x,y) grid. How would i plot this data.
Star Strider
Star Strider 2021-1-29
编辑:Star Strider 2021-1-29
Using that code, try this:
figure
imagesc(tally)
set(gca, 'XTick',(1:size(tally,2)), 'YTick',(1:size(tally,1)))
lix = sub2ind(size(tally), ix2, ix1);
text(ix1,ix2,compose('%d', tally(lix)), 'HorizontalAlignment','center', 'VerticalAlignment','middle')
Another option is the heatmap function.
EDIT — (29 Jan 2021 at 17:31)
Updated plot code.

请先登录,再进行评论。

更多回答(1 个)

Sumera Yamin
Sumera Yamin 2021-2-2
编辑:Sumera Yamin 2021-2-2
what about using pcolor() command? This can also plot the data as i want
  2 个评论
Star Strider
Star Strider 2021-2-2
The imagesc function and pcolor function are significantly different.
Compare these:
figure
imagesc(tally)
set(gca, 'XTick',(1:size(tally,2)), 'YTick',(1:size(tally,1)))
lix = sub2ind(size(tally), ix2, ix1);
text(ix1,ix2,compose('%d', tally(lix)), 'HorizontalAlignment','center', 'VerticalAlignment','middle')
and:
figure
pcolor(tally)
set(gca, 'XTick',(1:size(tally,2)), 'YTick',(1:size(tally,1)))
lix = sub2ind(size(tally), ix2, ix1);
text(ix1,ix2,compose('%d', tally(lix)), 'HorizontalAlignment','center', 'VerticalAlignment','middle')
The imagesc function is defined by the centres of the squares, the pcolor function is defined by the edges of the squares, so the pcolor plot is one less in each dimension.
Sumera Yamin
Sumera Yamin 2021-2-2
I see your point now. I tested your code on my script. somehow my matlab complains "Undefined function or variable 'tally'. One more question. with imagesc(), y axis is flipped. I mean it goes from top to bottom, instead of bottom to top. (This is not a problem, just being curious for the reason).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by