Matlab's plot command

  • #1
MathematicalPhysicist
Gold Member
4,294
203

Main Question or Discussion Point

I am using Matlab's 2017Rb academic license.

And while trying to operate the following sequence of commands:
Matlab:
x = linspace(0,2*pi,1000);
y = sin(2*x);
plot(x,y,'k−','linew',2); hold on;
I get the following warning:
Matlab:
Error using plot
Error in color/linetype argument.
What seems to be wrong in the above code?

Thanks.
 

Answers and Replies

  • #3
MathematicalPhysicist
Gold Member
4,294
203
So the error is in 'k-', how it should be?
'-k', yes now it works.
 
  • Like
Likes AgusCF and jedishrfu
  • #4
AgusCF
So the error is in 'k-', how it should be?
'-k', yes now it works.
But... '-k' make the same as 'k' I think...
 
  • #5
FactChecker
Science Advisor
Gold Member
5,706
2,112
So the error is in 'k-', how it should be?
'-k', yes now it works.
Interesting. The documentation says that the order of the symbols doesn't matter. So this is either a bug or there is something else going on.
 
  • Like
Likes AgusCF
  • #6
MathematicalPhysicist
Gold Member
4,294
203
Interesting. The documentation says that the order of the symbols doesn't matter. So this is either a bug or there is something else going on.
Did you try it in your machine?

I have Ubuntu 16.04 as the OS in this computer.
 
  • #9
MathematicalPhysicist
Gold Member
4,294
203
And... Why were you trying to plot 'k-'?
I copy-paste this snippet of code from some lecture notes I am reading.

So there I had this 'k-'.
 
  • #10
FactChecker
Science Advisor
Gold Member
5,706
2,112
Did you try it in your machine?

I have Ubuntu 16.04 as the OS in this computer.
I'm retired and no longer have access to MATLAB. I'm thinking about buying it just for these occasions.
 
  • #11
It's not a bug. And the order doesn't matter. The problem is you don't have a dash in there. It's some character that looks like a dash but isn't. When I paste in your code it shows the error message

Error using plot
Error in color/linetype argument.
Error in test1 (line 3)
plot(x,y,'k?','linew',2);


See the question mark indicating it doesn't know what that character is? If you get rid of that "dash" and replace it with a real dash (minus sign), it will work perfectly fine.
 
  • Like
Likes MathematicalPhysicist and FactChecker
  • #12
FactChecker
Science Advisor
Gold Member
5,706
2,112
It's not a bug. And the order doesn't matter. The problem is you don't have a dash in there. It's some character that looks like a dash but isn't. When I paste in your code it shows the error message

Error using plot
Error in color/linetype argument.
Error in test1 (line 3)
plot(x,y,'k?','linew',2);


See the question mark indicating it doesn't know what that character is? If you get rid of that "dash" and replace it with a real dash (minus sign), it will work perfectly fine.
Good catch! This is one of the frustrating things about copying and pasting text -- they can have characters and do other things you don't want. I like to paste into a programmer editor that I can control, like vim, just to be sure that the text is exactly what I wanted. I often have to replace things that I don't want in code. Then I copy the vim text and paste that into the target code.
 

Related Threads on Matlab's plot command

Replies
0
Views
3K
  • Last Post
Replies
1
Views
637
Replies
4
Views
13K
  • Last Post
Replies
1
Views
585
Replies
4
Views
787
  • Last Post
Replies
4
Views
24K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
1
Views
2K
Replies
5
Views
704
Replies
2
Views
5K
Top