Error in color/linetype argument

31 views (last 30 days)
Please help me, I am trying to run this code:
function perf(T,logplot)
if (nargin< 2) logplot = 0; end
colors = ['m''b''r''g''c''k''y'];
lines = ['-''-''-.''--'];
markers = ['x''x''x''x''v''^''o'];
[np,ns] = size(T);
minperf = min(T,[],2);
r = zeros(np,ns);
for p = 1: np
r(p,:) = T(p,:)/minperf(p);
end
if (logplot) r = log2(r); end
max_ratio = max(max(r));
r(find(isnan(r))) = 2*max_ratio;
r = sort(r);
clf;
for s = 1: ns
[xs,ys] = stairs(r(:,s),[1:np]/np);
option = ['-' colors(s) markers(s) ];
plot(xs,ys,option,'MarkerSize',3);
hold on;
end
axis([ 0.1 1.1*max_ratio 0 1 ]);
When I running, it appears error:
perf(T,2)
Error using plot Error in color/linetype argument.
Error in perf (line 20) plot(xs,ys,option,'MarkerSize',3);
If someone knows the answer, please help me.
  2 Comments
Stephen23
Stephen23 on 17 Sep 2018
@Chieu Nguyen: Your code does not make sense, for several reasons:
  • [] is a concatenation operator, not a "list" operator.
  • writing '' does not define a separator/delimiter, but simply is the character sequence for typing the character '.
You can easily try your code and see what it produces:
>> colors = ['m''b''r''g''c''k''y']
colors = m'b'r'g'c'k'y
In this case the square brackets are totally superfluous anyway, you would get exactly the same character vector without them:
>> colors = 'm''b''r''g''c''k''y'
colors = m'b'r'g'c'k'y
But it is unlikely that this is what you want. You need to learn about the basic data types (e.g. character array, cell array), and how to use them:
Chieu Nguyen
Chieu Nguyen on 19 Sep 2018
Thanks. I am beginner, I take this code from https://www.researchgate.net/publication/301625932/download. In my research, I need draw figures to compare something. But, I know Matlab a little bit, I mimic this code for my problem.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 17 Sep 2018
lines = ['-''-''-.''--'];
creates a character vector that contains -'-'-.'--
You need to learn how to use cell arrays of character vectors.

More Answers (2)

Steven Lord
Steven Lord on 17 Sep 2018
Depending on the release you're using, I recommend using string arrays instead.
colors = ["m", "b", "r", "g", "c", "k", "y"];
lines = ["-", "-", "-.", "--"];
markers = ["x", "x", "x", "x", "v", "^", "o"];
plot(1:10, 1:10, colors(3)+lines(4)+markers(5))
Note that this is different from concatenating the strings together using [], which will not work.
doesNotWork = plot(1:10, 1:10, [colors(3),lines(4),markers(5)])
Using + to combine the three scalar string arrays makes a new scalar string whose contents are the contents of the shorter strings concatenated, while using [] makes a larger string array each element of which is one of the original strings. The two string arrays works and doesNotWork defined below look different and have different sizes.
works = colors(3)+lines(4)+markers(5)
doesNotWork = [colors(3), lines(4), markers(5)]
whos works doesNotWork
  2 Comments
Chieu Nguyen
Chieu Nguyen on 19 Sep 2018
Thank for your answer. I am the beginner, I need to use Matlab comparing Cpu time... in my research. I just know Matlab a little bit, now I am trying to use Matlab to draw the figure. I also follow your code to get my problem ("Proximal Gradient Algorithm"). I also have a question, when I use "Accelerated proximal gradient methods", Cpu time which I obtain worse than "Proximal Gradient Algorithm". I don't know why.
Chieu Nguyen
Chieu Nguyen on 19 Sep 2018
Sorry, I have mistaken you are Stephen Boyd.

Sign in to comment.


kaushik gupta
kaushik gupta on 2 Nov 2020
clc;
clf;
close all;
clear all;
x1=('Enter the sequence x:');
g=x1(end:-1:1);
i=length(x1);
j=length(g);
cov=zeros(1,i+j-1);
for k=i;
for i=j;
cov(k+i-1)=cov(k+i-1)+x1(k)*g(i);
end;
end;
m=0:length(x1)-1;
subplot(2,1,1);
stem(m,x1);
grid on;
axis([-1 length(cov) min(cov)-2 max(cov)+2]);
xlabel('...');
ylabel('original sequence');
title('Autocorrelation');
  2 Comments
kaushik gupta
kaushik gupta on 2 Nov 2020
when i was running , it appears error:
Error using stem (line 40)
Error in color/linetype argument.
Error in mathlab9_1 (line 17)
stem(y,x1);
Walter Roberson
Walter Roberson on 2 Nov 2020
The error message shows y and x1 but your posted code shows no y. You also did not show us sample inputs.

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!