Incorrect number of inputs or outputs for function linspace

8 Comments

clc
clear
x=0:pi/100:2*pi;
y=sin(x);
z=linspace(1,100)
z = 1×100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
The default for linspace() is 100 points.
If your linspace() is complaining then somehow you are getting a different linspace. What shows up for
which -all linspace
/MATLAB/toolbox/matlab/elmat/linspace.m /MATLAB/toolbox/matlab/datatypes/datetime/@datetime/linspace.m % datetime method /MATLAB/toolbox/matlab/datatypes/duration/@duration/linspace.m % duration method /MATLAB/toolbox/parallel/gpu/@gpuArray/linspace.m % gpuArray method /MATLAB/toolbox/parallel/parallel/@distributed/linspace.m % distributed method /MATLAB/toolbox/parallel/parallel/@codistributed/linspace.m % codistributed method /MATLAB/toolbox/parallel/parallel/@codistributor1d/linspace.m % codistributor1d method /MATLAB/toolbox/parallel/parallel/@codistributor2dbc/linspace.m % codistributor2dbc method /MATLAB/toolbox/symbolic/symbolic/@symfun/linspace.m % symfun method
Also there is an additional error line for any new code i run although it doesnt involve linspace. it goes like this
Warning: Error updating ButtonImage.
Undefined function 'linspace' for input arguments of type 'double'.
it is repeated multiple times.
for further context, I did cut and paste the r2023 version from the original c folder to g recently.
It should be returning something similar to those in Walter’s Comment.
Run these from a script or your Command Window:
restoredefaultpath
rehash toolboxcache
Then try your original code again and report the results.
for further context, I did cut and paste the r2023 version from the original c folder to g recently.
That's temerarious.
The MATLAB that you copied from C: to G: recently appears to not be complete. If you need it to be stored in G: drive you should remove the G: version and uninstall from C: and then use the installer to install into G: directly.

Sign in to comment.

Answers (1)

Even if it is a matter of personal taste, for unit steps I usually prefer to do:
z1 = 1 : 100;
Nontheless, this should also work:
z2 = linspace(1, 100);
isequal(z1, z2)
ans = logical
1
Are you sure didn't create a function called linspace?
Have you tried to reset the path and clear the Workspace?
Try to restart Matlab and run it again.

Products

Release

R2023a

Tags

Asked:

on 5 Jun 2023

Commented:

on 5 Jun 2023

Community Treasure Hunt

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

Start Hunting!