Error trying to define an output function

Hello to everybody!! I can't understand how to correctly define an output function. I tried to define a function which plot the histogram of residuals on each iteration on this way:
function stop=his(x,optimValues,state)
stop=false;
switch state
case 'init'
figure
title('residual_plot')
case 'iter'
plot(histogram(optimValues.residual,15))
otherwise
end
But I recived this error:
Error using plot
Not enough input arguments.
Error in his (line 8)
plot(histogram(optimValues.residual,15))
I used lsqnonlin with 'OutputFcn' option.
I hope somebody could help me. Thanks

 採用された回答

Steven Lord
Steven Lord 2016 年 12 月 9 日

1 投票

The histogram function creates its own graphics object. There's no need (and indeed it shouldn't work) to pass a histogram handle into plot.
Note that as your code is written, creating a histogram at each call to the output function with the 'iter' flag will clear the histogram from the previous iteration since you haven't turned hold on. Is that what you want to do?

1 件のコメント

MtPt
MtPt 2016 年 12 月 9 日
Thanks, now it works! I thought it could show me histograms "dynamically" during iteration, but it doesn't work. I will search other solutions. I thank you for the answer

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 12 月 9 日

0 投票

I don't know what the purpose of stop is. You don't even use it, and you shouldn't even use it because it's a built-in function that stops the time.
histogram does the plotting by itself, so don't pass it to plot(). Just call it:
histogram(optimValues.residual, 15);
grid on;
You should fancy it up by setting xlabel and ylabel, you can set the bar color, and the bar edge color and bar width, etc.

1 件のコメント

MtPt
MtPt 2016 年 12 月 9 日
I know I have learnt it after sending my question

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

カテゴリ

質問済み:

2016 年 12 月 9 日

コメント済み:

2016 年 12 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by