I have the following for-loop
for i=0:0.001:4000;
if feval(sFit,2,i) <= 0.9
currentY = i;
break;
end
end
returnValue = feval(sFit,2,currentY+20);
I'm evaluating an sFit-Object inversely for a z = 0.9 and x = 2 to get the y-value. (The sFit is monotonically decreasing with x and y). After the Loop, I evaluate the sFit-object "conventially" with X and Y to get Z as a result.
Unfortunately this takes forever to compute, as the feval-function is called many times.
Is there any way to inversely evaluate a sfit-object quicker? I want to get the y-value for given z and x-values immediately, without any loop.

2 件のコメント

José-Luis
José-Luis 2016 年 7 月 6 日
What is it you are trying to achieve?
Andreas Harter
Andreas Harter 2016 年 7 月 6 日
The z-values range from 0 to 1 and describe a degeneration process. Depending on the input values of x and y the degeneration is stronger or weaker. The sFit-Object is a surface-Fit of Lab-Data that I use as a look-up-table for my real-time-inputs of x and y.

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

 採用された回答

Steven Lord
Steven Lord 2016 年 7 月 6 日

1 投票

Use fzero. In this example, when fzero finds a zero of myfun that value of y will satisfy sf(0.5, y) - 1 = 0 or sf(0.5, y) = 1.
% Sample data
[x, y, z] = peaks;
% Perturb the Z data slightly
z = z + rand(size(z));
% Create a surface fit object
sf = fit([x(:) y(:)], z(:), 'poly22');
% Create the function on which fzero will operate
myfun = @(y) sf(0.5, y)-1;
% Call fzero with an initial guess of y = 2.
desiredY = fzero(myfun, 2);
% Check by evaluating the fit
shouldBeEqualTo1 = sf(0.5, desiredY)

1 件のコメント

Andreas Harter
Andreas Harter 2016 年 7 月 6 日
Thank you, that did the trick!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by