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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

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