Filter löschen
Filter löschen

How to Prevent Lowess 3D Curve From Dipping into Negative Values

4 Ansichten (letzte 30 Tage)
CMatlabWold
CMatlabWold am 28 Okt. 2020
Kommentiert: CMatlabWold am 28 Okt. 2020
Hi,
I have a code. The Z value represents total complaints. When I run the code to get a 3D scatterplot with Lowess curve, the curve dips into negative values. Since it is impossible to have a negative value of complaints, this is a problem for me.
I need the Lowess curve to stay in the positive realm. I'd appreciate any help.
This is my code:
function [fitresult, gof] = createFit1(x, y, z)
ss0 = readtable('StatenIsland3D.xlsx')
x = ss0{:,1}
y= ss0{:,2}
z = ss0{:,3}
[xData, yData, zData] = prepareSurfaceData( x, y, z );
% Set up fittype and options.
ft = fittype( 'lowess' );
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% Plot fit with data.
figure( 'Name', 'Staten Island' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'Staten Island', 'z vs. x, y', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'x', 'Interpreter', 'none' );
ylabel( 'y', 'Interpreter', 'none' );
zlabel( 'z', 'Interpreter', 'none' );
grid on

Antworten (1)

Image Analyst
Image Analyst am 28 Okt. 2020
Did you try
fitresult = max([0, fitresult]); % bump negative values up to zero.
  1 Kommentar
CMatlabWold
CMatlabWold am 28 Okt. 2020
If I add it under
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
fitresult = max([0, fitresult])
I get this message:
Error using fittype/horzcat (line 6)
Concatenation of double objects not permitted.
Error in LowessTrial2 (line 17)
fitresult = max([0, fitresult])

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by