Retrieve data from arbitrary point from contourf plot

조회 수: 2 (최근 30일)
Mechrod
Mechrod 2019년 4월 10일
댓글: Mechrod 2019년 4월 10일
Hi.
I'm plotting a x,y,T using 2D plot. Using the code below
[Xr,Yr,Tr] = griddata(x,y,T,unique(x),unique(y)','v4'); % http://www.alecjacobson.com/weblog/?p=1532
figure();
colormap(jet);
[cc,hh]=contourf(Xr,Yr,Tr,'Showtext','on','LevelList',[400 600 700 800 900 1000 1100 1200 1300]);
hold on
colorbar;
triplot(dt,'LineWidth',0.01,'color','k');
axis([0 0.006 0 0.003]);
i get this plot. But when i try to retrieve the T data from the plot, it always snaps to the nearest point of the grid data tha generated the plot.
deletar.PNG
Is there a way to retrive (programmatically) the T value from an arbitrary (x,y) position? Something like i have when using Tecplot (below), where i click the plot and it retrieves the interpolated values used the generate the image. My objective is to enter a x,y value and retrive the T value from that point.
del2.PNG
  댓글 수: 1
Mechrod
Mechrod 2019년 4월 10일
I found a way that meets my requirements, after carefully reading the meshgrid and griddata help. I hope it can help someone else.
First i set up 2 vectors containing x and y positions of my points of interest, xp and yp. Then use griddata to generate interpolated values (Tp) for those positions. (Thats all i needed!)
x = pos_nos(:,1); % original data
y = pos_nos(:,2);
T = pos_nos(:,3);
%
xp = [0.0001 ; 0.0008 ; 0.0014];
yp = [0.0001 ; 0.0008 ; 0.0014];
%
Tp = griddata(x,y,T,xp,yp,'natural');
After that, i can use meshgrid to generate a fine mesh where the results will be interpolated, in case i need to extract more data. Then i just use griddata and plot the image.
[xg,yg] = meshgrid(0:0.0001:0.006, 0:0.0001:0.004);
[Xr,Yr,Tr] = griddata(x,y,T,xg,yg,'natural');
figure();
colormap(jet);
[cc,hh]=contourf(Xr,Yr,Tr,'Showtext','on','LevelList',[400 600 700 800 900 1000 1100 1200 1300]);

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by