[generated code] create figure function: missing input arguments

12 visualizzazioni (ultimi 30 giorni)
Hello everybody,
I have autogenerated code for a surface plot function using the Curvefitting tool:
function [fitresult, gof] = createFit(X, Y, Z)
%CREATEFIT(X,Y,Z)
% Create a fit.
%
% Data for 'Interpolant' fit:
% X Input : X
% Y Input : Y
% Z Output: Z
% 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 03-Dec-2017 20:29:16
%%Fit: 'Interpolant'.
[xData, yData, zData] = prepareSurfaceData( X, Y, Z );
% Set up fittype and options.
ft = 'linearinterp';
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% Plot fit with data.
figure( 'Name', 'Interpolant' );
plot( fitresult, [xData, yData], zData );
% Label axes
xlabel 'Dryer length (m)'
ylabel 'Dryer width (m)'
zlabel 'Air velocity (m/s)'
grid on
view( 0, 90.0 );
I can call this fnc easily by just providing my three input arguments (my X-axis,Y-axis and Z-data; all onecolumnvectors)
However, afterwards I always have to go into the 'interactive Plot tools'-button in the top right corner to be able to modify my graph in detail.
I need to change some x&y-ticks as well as labels and general appearance settings. From there I auto-generate this code:
function createfigure1(xdata1, ydata1, zdata1, XData2, YData2, ZData2)
%CREATEFIGURE1(XDATA1, YDATA1, ZDATA1, XDATA2, YDATA2, ZDATA2)
% XDATA1: surface xdata
% YDATA1: surface ydata
% ZDATA1: surface zdata
% XDATA2: line xdata
% YDATA2: line ydata
% ZDATA2: line zdata
% Auto-generated by MATLAB on 07-Jan-2018 15:19:11
% Create figure
figure1 = figure('Name','Interpolant','Color',[1 1 1]);
% Create axes
axes1 = axes('Parent',figure1);
hold(axes1,'on');
% Create surf
surf(xdata1,ydata1,zdata1,'Parent',axes1,'PickableParts','none',...
'Tag','curvefit.gui.FunctionSurface');
% Create line
line(XData2,YData2,ZData2,'Parent',axes1,'MarkerFaceColor',[0 0 1],...
'MarkerEdgeColor',[1 1 1],...
'Marker','o',...
'LineStyle','none');
% Create xlabel
xlabel('Dryer length (m)');
% Create ylabel
ylabel('Dryer width (m)');
% Create zlabel
zlabel('Air velocity (m/s)');
% Create title
title('ISD ''tube'' - OutdoorTrial1, 5.1.18, AbsorberCover');
%%Uncomment the following line to preserve the X-limits of the axes
% xlim(axes1,[0 14.2]);
%%Uncomment the following line to preserve the Y-limits of the axes
% ylim(axes1,[0 1.52]);
view(axes1,[0 90]);
box(axes1,'on');
grid(axes1,'on');
% Set the remaining axes properties
set(axes1,'CLim',[0 0.5],'XTick',[0 1 2 2.65 4 6 8 10 12 13.6 14.2],...
'XTickLabel',{'0','1','2','2.65','4','6','8','10','12','13.6','14.2'},...
'YTick',[0 0.5 0.635 0.885 1 1.5],'YTickLabel',{'0','0.5','','','1','1.5'});
% Create colorbar
colorbar('peer',axes1);
This code in turn needs much more input arguments than I have available, and it lets me know in an error message.
So my question is: how do I use this function, and where can I get the additional needed input arguments? Also I would be glad if somebody could break this apart and make it a little easier for me to understand.
Thank you in advance. Using MatLab R2015b

Risposte (1)

Kris Fedorenko
Kris Fedorenko il 9 Gen 2018
Hi Vuc,
Here is a quick and dirty answer, I hope it helps.
xdata1, ydata1, zdata1 in the createfigure1 function correspond to
[xData, yData, zData] = prepareSurfaceData( X, Y, Z )
You can see that later in "createfigure1" they are used to plot the surface.
XData2, YData2, ZData2 describe the line of the fit.
If you look at the code modifying the plot, you can see that it doesn't really use these arguments. It does however need the handle to the axes (which the "plot" function returns). You might be able to simplify the code using this information.
Also note that you can customize the plot in the plot function itself .

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by