Is there a way to extract data from surface graphics in the curvefitting toolbox?

5 views (last 30 days)
Hello to all
I'm doing some interpolation problems using curve fitting toolbox.
I would like to know if there is any way to extract the x, y z of the surface graphic that appear in the curve fitting window?
Thank you
Pedro
  3 Comments
Pedro Pinto
Pedro Pinto on 15 Feb 2019
The question is that we generate a surface graph with the curve fitting toolbox and want to use the same x,y,z data to create a heat map on another image software. The dificulty is that we cannot get the x,y,z variables of the interpolated graphic to use them in the next phase. If anyone has some ideas we thank in advance
Pedro
Walter Roberson
Walter Roberson on 15 Feb 2019
Tomorrow I will do some testing on how to extract the exact information . It will not be easy as it involves undocumented graphics containers if I recall correctly .

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 17 Feb 2019
Experimenting, I find:
s = findall(groot,'tag','curvefit.gui.FunctionSurface');
x = s.XData;
y = s.YData;
z = s.ZData;

Pedro Pinto
Pedro Pinto on 17 Feb 2019
Dear Walter
I was trying and it give an error
The code, generated by curvefitting toolbox is this one:
function [fitresult, gof] = createFit1(x, y, Pontos)
%CREATEFIT1(X,Y,PONTOS)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : x
% Y Input : y
% Z Output: Pontos
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 17-Feb-2019 16:25:20
%% Fit: 'untitled fit 1'.
[xData, yData, zData] = prepareSurfaceData( x, y, Pontos );
% Set up fittype and options.
ft = 'thinplateinterp';
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'untitled fit 1', 'Pontos vs. x, y', 'Location', 'NorthEast' );
% Label axes
xlabel x
ylabel y
zlabel Pontos
grid on
where x, y and Pontos are the vectors of x,y,and z containing the data
  3 Comments
Pedro Pinto
Pedro Pinto on 17 Feb 2019
I tryed and now there are no more erros and i get a variable called ans with 1x1 sfit as value.
However i cannot get the values of the vectors in the full space.
So let me get the values
i have a 6 x 6 table of x,y data
x=1,2,3,4,5,6
y=1,4,2,7,4, 9
then for each x,y pair (ex, 1 x 1, 2 x 4, etc), i have the following z data:
Pontos: 43, 65, 7, 45, 98, 34
When i create the interpolation graphic in the curvefitt toolbox i get a surface continues graphic with x between 0 and 6, y between 0 and 10 and z between 0 and 100.
These are the values that i need to have in 3 new variables x1, y1 and z1 so i can pass them to excel and enter in the other software. It will be a continue surface x,y,z combinations based on the thin plate spline interpolation
For sure this is a simple question, but as this is my first approach to matlab world it's being difficult to get the values

Sign in to comment.


Pedro Pinto
Pedro Pinto on 17 Feb 2019
Here follows
  1 Comment
Walter Roberson
Walter Roberson on 17 Feb 2019
With that data, the code I posted works for me, both versions -- doing the findall() after the createFit1 routine has returned, or taking h(1) of the h = plot() handle in the createFit1 routine.
The x, y, and z values that are extracted are all 51 x 49, and you can surf(x, y, z) to reconstruct the plotted surface.

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!