Get fitting statistics from "solve"

Question
1) How do I get the graphs to update nicely during the fitting precces.
2) How do I get statistics from the fitting precess?
Hello, I wrote a fitting script using the example here https://www.mathworks.com/help/optim/ug/fit-ode-problem-based-least-squares.html which was very helpful. The code is working fine, I just want to make it flashier, and report some statistics from the fit. Any advice would be appreciated.
I want to see each iteration of the fit, so I put plot commands in my function call RtoODE. However each time it plots, the first trace has lower y values than the next trace, meaning the y axis rescales each time. It's hard to see how the fit is changing when the y axis is constantly rescaling. Is there a better way to do this? Perhaps an option when calling "solve" that will show the iterations automatically?
I would also like to see the goodness of fit, such as the r^2. If I could get a plot of the goodness of fit for each iteration, showing the fit getting better and better, that would be wonderful. Is there a good way to do this?
I'm using MATLAB 2019a.
Thank you in advance!

답변 (3개)

Jerome Blair
Jerome Blair 2020년 3월 28일
편집: Walter Roberson 2020년 4월 11일

0 개 추천

You do all the plots once as follows:
p1 = plot(x1,y1,color1);
hold on
p2 = plot(x2,y2,color2);
etc.
Now set the y limits so they don't change:
ylim([ymin ymax])
Use values that will work for you.
Next is the code that changes all of the y arrays
Instead of plotting again you do
p1.YData = y1;
p2.YData = y2;
etc.
These changes to the YData field cause the plot to instantly change.
This sort of thing is covered in Chapter 17 of the MATLAB Graphics manual.

댓글 수: 1

george hargenrader
george hargenrader 2020년 4월 10일
using the
p1 = plot(x,y);
syntax works to some degree. But when y contains multiple lines then p1 will reference those lines. Any additional lines I add to the figure using hold on, are not referenced by p1.

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

Jerome Blair
Jerome Blair 2020년 4월 11일

0 개 추천

p1 can only reference 1 line. Additional lines must use p2, p3, etc., as in the example I sent. The different hanles, p1, p2, p3, etc., eg., can have any names you wish.

댓글 수: 1

george hargenrader
george hargenrader 2020년 4월 11일
p1 can reference multiple lines if they were plotted when p1 was initialized. For example the following can change the color.
p1 = plot(x,y); %Where y is a matrix, each row a line
p1(1).YData = new_y;
But when I use hold on to add more lines, p1 will not be able to access them.
So, while it's a neat idea, I don't think it helps me solve this particular problem.

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

Jerome Blair
Jerome Blair 2020년 4월 11일

0 개 추천

Of course p1 will not be able to access them. You have to acces them with p2 or p3--the handle that was used when theeh line was created--as in teh example I orginally sent.

카테고리

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

제품

질문:

2020년 3월 27일

편집:

2020년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by