필터 지우기
필터 지우기

transforming matrix after change of variables

조회 수: 1 (최근 30일)
María Jesús
María Jesús 2015년 11월 24일
답변: Walter Roberson 2015년 11월 25일
Hi,
I have a matrix M(r, t), which I would like to transform into a matrix N(x, y, t), where x = r*cos(theta), y = r*sin(theta). I would like to use this to generate a heat map using image() where it plots x against y with the color corresponding to the entry in the matrix. Is there a way to do this?
Thanks for the help!
  댓글 수: 2
the cyclist
the cyclist 2015년 11월 24일
What is stored in M? The value at a given (r,t) location? Is it a column vector? Do you have the corresponding values of r and t stored in corresponding vectors?
María Jesús
María Jesús 2015년 11월 24일
Yes, M has a value at each (r,t), it is a 100x100 array. r and t are each a 1x100 array

댓글을 달려면 로그인하십시오.

답변 (2개)

the cyclist
the cyclist 2015년 11월 24일
Assuming you are using t and theta interchangeably here, then I think it should just be
x = r.*cos(t);
y = r.*sin(t);
figure
imagesc(x,y,M)
  댓글 수: 1
María Jesús
María Jesús 2015년 11월 24일
They're meant to be different. Theta runs from 0 to 2pi and t from 0 to 0.2, although the vectors do have the same size.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2015년 11월 25일
image() and imagesc() and imshow() only deal with rectangular matrices aligned with the X/Y axes. When you pass x or y coordinates into image() or imagesc(), only the first and last values are paid attention to.
If you want an image with nonlinear coordinates you have a few choices:
  1. pcolor() or surf() with the coordinate grids and the image data. pcolor() is exactly equivalent to surf() viewed from above. Note that the coordinates are taken to be of vertices and color is interpolated based upon the color of the vertices
  2. use patch() in texturemap mode to draw the image stretched on to the surface
  3. use a gridded interpolant and sample the function at a rectangular grid that is then an image that can be used with image() or imagesc()
  4. probably not for this case but in some cases, use one of the image transforms
  5. you might be able to use iradon()

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by