Borrar filtros
Borrar filtros

Draw sigmoid curve using points

20 visualizaciones (últimos 30 días)
Raziur Rahman
Raziur Rahman el 28 de Ag. de 2015
Comentada: Star Strider el 29 de Ag. de 2015
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?

Respuestas (1)

Star Strider
Star Strider el 29 de Ag. de 2015
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 comentarios
Cedric
Cedric el 29 de Ag. de 2015
Editada: Cedric el 29 de Ag. de 2015
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 el 29 de Ag. de 2015
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by