필터 지우기
필터 지우기

Draw sigmoid curve using points

조회 수: 20 (최근 30일)
Raziur Rahman
Raziur Rahman 2015년 8월 28일
댓글: Star Strider 2015년 8월 29일
I have 8 x-axis points, like this "-5.99,-4.82,-3.68,-2.52,-1.38,-0.22,0.92,2.07" and their y-axis points are "-58,-7.5,-1.7,7.04,-58,-70,-73,-73". How to draw a sigmoid curve using these points?

답변 (1개)

Star Strider
Star Strider 2015년 8월 29일
This is not going to be easy because your data don’t approximate a Sigmoid function. However, if you want to experiment, I added a y-offset and a scaling parameter (here b(1) and b(2) respectively), as well as x-offset and scaling parameters (the other two) to the standard sigmoid function as the objective function.
x = [-5.99,-4.82,-3.68,-2.52,-1.38,-0.22,0.92,2.07];
y = [-58,-7.5,-1.7,7.04,-58,-70,-73,-73];
fn = @(b,x) b(1) + b(2)./(1 + exp(b(3)-b(4).*x)); % Sigmoid Function (Objective Function)
SSECF = @(b) sum((y - fn(b,x)).^2); % Sum-Squared-Error Cost Function
B0 = [-40; -100; -5; 0.1]; % Initial Parameter Estimates
[B,SSE] = fminsearch(SSECF, B0); % Estimate Parameters (B), Return Sum-Squared Error (SSE)
xp = linspace(min(x), max(x));
figure(1)
plot(x, y, 'bp')
hold on
plot(xp, fn(B,xp), '-r')
hold off
grid
You will probably have to experiment to get the result you want. I leave the rest to you.
  댓글 수: 2
Cedric
Cedric 2015년 8월 29일
편집: Cedric 2015년 8월 29일
Hey Star, have you seen this? If not -> copy/paste/run the code from the comment! I am not sure whether you check your TMW emails or not, so I don't know if you saw my answer to your "welcome back" email a month ago as well as the ref. to this thread (that I sent to you lately). I let you delete this comment once you've read it ;-)
Cheers,
Cedric
Star Strider
Star Strider 2015년 8월 29일
Hi Cedric, my Gmail account (where I direct my File Exchange email) has been inundated by political stuff of late, so I didn’t see it last Saturday. I just now located it and forwarded it to my personal email, and also opened the link. I’ll go back and copy-paste-run with a new .m file. (I have a subdirectory in my MATLAB user path specifically for your code.) I’ll reply to it as well to your account with my personal email.
Thank you for the fun plot! Right now, I have to play with the code to bring the plot to the top. This puts figure(1) on top for a second then the figure goes to the back (in R2015a, Win 8.1):
hf = figure() ;
uistack(hf, 'top') % Added Just After The ‘figure’ Call
I can see it the animated plot fine if I just hover over the MATLAB item in the toolbar, but displaying it on my system as a normal plot in the foreground isn’t working, for a reason I haven’t figured out yet. Clicking on the plot in the toolbar doesn’t bring it up either. Usually, plots display without problems.
I would welcome anything I can learn from you about this, since my usual strategies aren’t working.

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

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by