Imagesc/Contourf and plotting correctly

14 visualizaciones (últimos 30 días)
William F.
William F. el 4 de Abr. de 2011
Thanks in advance for the help.
I have a series of coordinates in latitude, longitude, and depth (respectively called lat, long, and depth) and associated at each one of these points P(lat,long,depth) I have a value. The values for each of these points in contained in a 3d matrix called misfit(lat,long,depth). The idea is to make several imagesc (or contourf) plots to at varying depths to get an idea of my results and to have on each plot a point marking the minimum of the misfit (the matrix mentioned above). I contain the value and the coordinates of the minimum misfit (in that respective order) in the variable mini.
The problem is that when I do: figure; hold on imagesc(lat, long, misfit(:,:,mini(4))); plot(lat(mini(2)), long(mini(3)), 'ok', 'markersize', 15, 'markerfacecolor', 'k'); hold off
I have a surface that's minimum does not correspond at all to the point I plotted. When I go to the data cursor and go to the location of mini, it gives me back a value that is not at all the minimum value I want.
What am I missing here?

Respuesta aceptada

William F.
William F. el 6 de Abr. de 2011
I was expecting to see the same value and associated coordinates that I found from the misfit matrix directly, however the data cursor gave me different coordinates (and whether they're close or not doesn't matter as they should be exactly the same).
I was expecting imagesc() to plot exactly the coordinates I gave it with the associated values it found in misfit. However I found out that the problem stemmed from the fact that imagesc() doesn't actually use the lat/long cooridnate vectors I fed it and instead takes the starting point, the ending point, and the length of lat/long and then constructs the following vector to use as the coordinates of the misfit matrix:
[lat(1):(lat(end)-lat(1))/length(lat):lat(end)]
My problem was to use lat/long vectors that did not have a constant interval (doing a monte carlo search) so imagesc() ended up using its own lat/long vectors and everything got misplaced and skewed. Sorta disappointing imagesc() would act like this, but oh well.
Thank you Walter and Teja for your responses.
PS. Thanks for the tip with min(misfit(:))! I always found min(min(min( ad infinitum was really clunky.
  1 comentario
Teja Muppirala
Teja Muppirala el 7 de Abr. de 2011
Aaaa! Now I gotcha. Yeah, IMAGESC calls IMAGE which distributes the points evenly between the min and max values. That can be a problem.
Here is one (heavy-handed) workaround to make the data cursor go right on the points:
lat2 = interp1(1:numel(lat),lat,0.5:0.5:numel(lat)+.5,'linear','extrap');
lon2 = interp1(1:numel(lon),lat,0.5:0.5:numel(lon)+.5,'linear','extrap');
M = misfit(:,:,mini(4));
M = blkdiag(kron(flipud(M),[1 1;1 1]),nan);
h_surf = pcolor(lat2,lon2,M);
set(h_surf,'edgecolor','none');
axis(axis + [-2 2 -2 2]);

Iniciar sesión para comentar.

Más respuestas (3)

Teja Muppirala
Teja Muppirala el 4 de Abr. de 2011
This is just a guess, but depending on how you found your minimum locations, the x and y values (mini(2) and mini(3)) might be reversed. Indexing into matrices goes vertically, then horizontally, while the PLOT function takes x (horizontal) values then y (vertical) values.
To illustrate:
M = zeros(5);
M(1,4) = -1
imagesc(M)
hold on
plot(1,4,'wx')
M(1,4) is definitely the minimum. But you can see that plot(1,4) has the coordinates in the wrong order. Reverse them and it will be ok.
plot(4,1,'wx')
  2 comentarios
William F.
William F. el 5 de Abr. de 2011
When I compare the coordinates of the minimum point I plotted with the plot() line, it corresponds with the x and y axis of the imagesc plot. The problem lies with the imagesc plot: when I call the misfit(lat,long,depth) at the command line with the minimum coordinates I get the minimum value I want. However when I plot the misfit with imagesc, the data cursor at the same exact coordinates gives me a value that is not the same as the value I have when I call for it at the command line. Basically:
@ the command line: misfit(latmin, longmin, depthmin) = minimum value. Everything is happy and dandy.
@ the imagesc plot with data cursor: misfit(latmin, longmin, depthmin) = some other value that is not all the minimum. The minimum on the imagesc surface is located at some other coordinates that have nothing to do with the real minimum coordinates.
Thanks for taking the time to reply.
Teja Muppirala
Teja Muppirala el 6 de Abr. de 2011
At the command line, misfit(latmin, longmin, depthmin) = minimum value = A = 0.067443 according to the 3rd line printed.
The imagesc plot with data cursor: misfit(17.89 which is very near latmin, -99.51 which is very near longmin, depthmin) = 0.06744
0.067443 is very close to 0.06744, so I'm having trouble seeing the problem. What value were you expecting to see?

Iniciar sesión para comentar.


William F.
William F. el 6 de Abr. de 2011
To better explain my problem: http://img9.imageshack.us/f/imagescprob.png/
  1 comentario
William F.
William F. el 6 de Abr. de 2011
Woops, and yes, mini(4) = d in the above picture: http://img543.imageshack.us/i/imagescprob2.png/

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 6 de Abr. de 2011
The coordinates that you give in the first two arguments for imagesc() are the locations of pixel centers of the bottom-right and upper-left corners. This can result in the image being larger than you expect. Still, though, that should not affect the data cursor.
In your code, you use
A = min(min(min(misfit))); i = find(misfit == A); [r,c,d] = ind2sub(size(misfit),i);
This can be better written
[A, i] = min(misfit(:)); [r, c, d] = ind2sub(size(misfit),i);
The code you have is inefficient because find can return the positions directly, [r, c, d] = find(misfit == A); However the code is also risky because there might be more than one location which exactly matches the minimum and then find would return multiple values, which you are not prepared to deal with. min() can return an array index directly and will only return one index in the form I show.
The "Index:" that shows up in your datatip is the color index for pseudo-colored images. The value it will have will depend upon the current CLim setting. Normally (e.g., with the code you seem to have used) it would correspond to the array value. In order to find out more surely, record the handle of the image that imagesc() generates and get() the CData property of that handle and examine the matrix.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by