how to show only a part of a surface fit that falls within a certain polygon

1 回表示 (過去 30 日間)
Dany
Dany 2015 年 2 月 12 日
コメント済み: Dany 2015 年 2 月 15 日
Hi, i have created a surface fit using the next code:
*ft = 'thinplateinterp';
[fitresult, gof] = fit( [xData, yData], zData, ft );*
the next thing i want to do is to plot that surface, so i use:
*figure( 'Name', 'untitled fit 2' );
h = plot(fitresult);*
the problem is that it creats the surface over areas that i am not intrested in, so i have two parameters x and y that creats a closed polygon and i would like to show the part of the surface that falls within this polygon. how can i do it? is it even possible?
thank you for your help

採用された回答

Mike Garrity
Mike Garrity 2015 年 2 月 12 日
The simplest is to set zData to nan for the points you want to discard. Consider this example:
[x,y,z] = peaks;
px = [0 4 2];
py = [-1 -1 2];
inpts = inpolygon(x,y,px,py);
z(inpts) = nan;
surf(x,y,z)
  3 件のコメント
Mike Garrity
Mike Garrity 2015 年 2 月 12 日
When you said "show" I assumed you meant you wanted to modify the surface which gets created by the plot method. Also, to discard the data outside, just do z(~inputs). Like so:
[x,y,z] = peaks;
f = fit([x(:),y(:)],z(:),'poly23');
h = plot(f);
px = [-1 3 3 2 2 0 0 -1];
py = [-1 -1 0 0 1 1 0 0];
inpts = inpolygon(h.XData,h.YData,px,py);
h.ZData(~inpts) = nan;
Dany
Dany 2015 年 2 月 15 日
ok. thank you. but one problem though.
when i write
inpts = inpolygon(h.XData,h.YData,px,py);
i get this error:
Attempt to reference field of non-structure array.
it is like "h" does not have any properties.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by