What am I doing wrong?

I am following a line of code from a MATLAB book line for line but keep getting this error code and I'm not understanding why.
>> f = @(mu,x) mu*x-x.^3;
>> x = linspace(-5,5);
>> f_many = [f(-5,x) f(0,x) f(5,x) f(45,x)];
>> plot(x,f_many)
Error using plot
Vectors must be the same length.

Respuestas (1)

Abdolkarim Mohammadi
Abdolkarim Mohammadi el 22 de Sept. de 2020
Editada: Abdolkarim Mohammadi el 22 de Sept. de 2020

2 votos

For drawing multiple line plots at once, you should have one column vector for each line. You just need to have x as a column vector. f_many will also be an array with four columns.
x = linspace (-5,5)';

Categorías

Más información sobre Line Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Sept. de 2020

Editada:

el 22 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by