Why only scatter function is not working?

x=27:0.5:29
y= [2.41 2.4 2.395 2.39 2.38]
scatter(x,y)
scatter plot is not showing by using thus code.Please clarify.

10 commentaires

It's working here.
x=27:0.5:29;
y= [2.41 2.4 2.395 2.39 2.38];
scatter(x,y)
What is the output for you?
Walter Roberson
Walter Roberson le 11 Oct 2023
Did you accidentally create a variable named scatter?
Type
clear scatter
at command line and all trouble will (almost certainly) disappear! :)
It's what all the above were driving at -- you undoubtedly accidentally created a variable scatter the is aliasing the function.
If you created another m-file function by the name of scatter, that would do it, too, but that's much less likely -- but the which would show it up. In that case, of course, if it is a function you need/want, then rename it something like "myscatter.m" or, if it was an accident, just delete it.
Bruno Luong
Bruno Luong le 12 Oct 2023
If scatter was a variable accidently created then scatter(x,y) would throw an error. So I don't think this is the case.
Walter Roberson
Walter Roberson le 12 Oct 2023
You are correct that with non-integer x and y and if scatter was a numeric variable (most types of variables actually) then scatter(x,y) would generate an error. (But there are some places it would not, such as if scatter happened to be a function handle with 2 parameters)
However... I have seen in the past that people have said that an output is "not showing" (or similar wording about not seeing the output) when the code was generating error messages. People do not always notice the error messages, or do not always think they are significant.. or sometimes they just don't mention error messages that look pretty significant, expecting that we will immediately know the error message just be reading their code...
GD
GD le 12 Oct 2023
Modifié(e) : GD le 12 Oct 2023
@Cris LaPierre sir after running this code "which scatter -all" I got following result
GD
GD le 12 Oct 2023
@dpb Thank you sir for your suggestion. I hve written clear scatter in command window. But same problem I am facing.
GD
GD le 12 Oct 2023
GD
GD le 12 Oct 2023
@Dyuman Joshi Sir the following error is coming.
GD
GD le 12 Oct 2023
@Cris LaPierre sir I am getting this error after putting scatter(x,y)

Connectez-vous pour commenter.

 Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 12 Oct 2023

0 votes

You have named your script after a built-in MATLAB function i.e. error.
It's not a good idea to name variables or scripts or user-defined functions by using built-in function names.
Rename the script and run it again to check if there are any other errors or not.

6 commentaires

GD
GD le 12 Oct 2023
sir I changed the filename.But same error is coming.
Dyuman Joshi
Dyuman Joshi le 12 Oct 2023
The name of the file is still error.m
Change it to something else, like Script.m or MyFile.m
Bruno Luong
Bruno Luong le 12 Oct 2023
Modifié(e) : Bruno Luong le 12 Oct 2023
C:\Users\Debarati Ghosh\Documents\MATLAB\error.m is obviously your file not MATLAB file. You shadow MATLAB stock function, prevent MATLAB to work properly.
There is another problem if your call to scatter, that is why it tries to trigger an error.
GD
GD le 12 Oct 2023
@Dyuman Joshi Sir the filename is untitled.m. How to change error.m file?
Bruno Luong
Bruno Luong le 12 Oct 2023
Modifié(e) : Bruno Luong le 12 Oct 2023
How to change error.m file?
Open Windows File explorer Browse to C:\Users\Debarati Ghosh\Documents\MATLAB
Check if error.m is size 0, if yes delete it.
If not rename error.m to something else, e.g. myerror.m then change accordingly what of your mfile that call error to myerror.
I short just basic usage of computer.
GD
GD le 12 Oct 2023
@Dyuman Joshi Going by your suggestion it is done.Now I am getting proper result.Thank you sir.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by