Filter löschen
Filter löschen

How can I evaluate the cftool grid/mesh/ surface that Matlab itself creates?

3 Ansichten (letzte 30 Tage)
I have an efficiency map of raw data points (x,y,z). With cftool I have interpolated those points, to get a 3d map and a iso efficiency lines map. This map would represent an efficiency map, where "z" is the efficiency. I would like to extract the values used to build the plot, in a matrix format. (I'm assuming that Matlab, to create the graph, use a grid/ mesh to interpolate). At the moment the only way I found is: CurveFittingTool >Fit >save to Workspace: tick all the boxes (fittedmodel, goodness, output). This creates several object. Than,I have defined two vectors xq and yq to get values zq in some different points of the map. Instead of extracting values in xq,yq, I want to work with the grid/mesh that Matlab has produced. So I have the plot, but I'd like to use the data for other calculations.
I'd like to know also how to make the process automatic. In particular how to save to the workspace fittedmodel, goodness, output (that I'm assuming contains the data that I need) without going through CurveFittingTool GUI. At the moment I have auto-generated the code using >File >Generate Code, but it doesn't have the saving part.
Thank you

Akzeptierte Antwort

Steven Lord
Steven Lord am 12 Sep. 2016
The generated code should contain a command to create the fit. Evaluate the fit stored in the variable returned by that command on your grid of data.
% Generate coarse data
[x, y] = meshgrid(-2:2);
z = x.^2+y.^2-(x.*y)+rand(size(x));
% Fit coarse data and generate code interactively (do this step once)
cftool(x, y, z);
% Copy the commands from the generated code into your code to fit automatically
[xData, yData, zData] = prepareSurfaceData( x, y, z );
ft = fittype( 'poly22' );
[fitresult, gof] = fit( [xData, yData], zData, ft );
% Generate finer data and evaluate fit on finer data
[x1, y1] = meshgrid(-2:0.5:2);
z1 = fitresult(x1, y1);
% Create mesh plots. The black markers and lines are the coarse data, the cyan the fine data
mesh(x, y, z, 'Marker', 'o', 'FaceColor', 'none', 'EdgeColor', 'k');
hold on
mesh(x1, y1, z1, 'Marker', '+', 'FaceColor', 'none', 'EdgeColor', 'c');
Now if you want to repeat this process automatically, just comment out the cftool command.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by