Fixing Matlab Plot Error: Invalid Color/Linetype Argument

  • MATLAB
  • Thread starter MathematicalPhysicist
  • Start date
  • Tags
    Plot
In summary: 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.In summary, you were trying to use the 'k-' command to plot 'k-'. The problem is that you don't have a dash in there and the command gives you an error. You can fix the problem by getting rid of the dash and replacing it with a real
  • #1
MathematicalPhysicist
Gold Member
4,699
371
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.
 
Physics news on Phys.org
  • #3
So the error is in 'k-', how it should be?
'-k', yes now it works.
 
  • Like
Likes AgusCF and jedishrfu
  • #4
MathematicalPhysicist said:
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
MathematicalPhysicist said:
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
FactChecker said:
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.
 
  • #7
AgusCF said:
But... '-k' make the same as 'k' I think...
Yes, it works as well.
 
  • Like
Likes AgusCF
  • #8
MathematicalPhysicist said:
Yes, it works as well.
And... Why were you trying to plot 'k-'?
 
  • #9
AgusCF said:
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
MathematicalPhysicist said:
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
Image Analyst said:
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.
 

1. What does the error "Invalid Color/Linetype Argument" mean in Matlab?

This error means that the color or line type you have specified for your plot is not recognized by Matlab. This could be due to a typo or using an incorrect color or line type code.

2. How can I fix this error in Matlab?

To fix this error, you will need to check your code and make sure that the color or line type you have specified is valid. You can refer to the Matlab documentation for a list of valid color and line type codes. You can also try using the color picker tool in the plot editor to select a valid color.

3. Can I use custom colors or line types in Matlab plots?

Yes, you can use custom colors or line types in Matlab plots by specifying their RGB values or using a custom line style. However, make sure that these custom values are valid and do not result in the "Invalid Color/Linetype Argument" error.

4. Why am I getting this error for only some of my plots in Matlab?

This error may occur if you are using different color or line type codes for different plots. Make sure that the codes you are using are valid for all plots. It is also possible that the error is only occurring for a specific plot due to a typo or incorrect code used only for that plot.

5. Can this error be caused by other factors besides invalid color or line type arguments?

Yes, this error can also be caused by using incorrect syntax for specifying color or line type, such as using a single quote instead of a double quote. It can also be caused by using a variable instead of a string for specifying color or line type. Make sure to check your code for any potential syntax errors that may be causing this error.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
567
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
10
Views
986
Back
Top