Filter löschen
Filter löschen

User defined color/linetype property

3 Ansichten (letzte 30 Tage)
Ryan
Ryan am 6 Mai 2014
In my code, I define some color and linetype properites:
marker = 'wo';
markerFaceColor_str = 'MarkerFaceColor';
markerFaceColor_val_str = 'w';
plotSymbol_str = ['''' marker '''' ',' '''' markerFaceColor_str '''' ',' '''' markerFaceColor_val_str ''''];
This gives me the string
'wo','MarkerFaceColor','w'
My plot statement (which gives me an "Error in color/linetype argument") is
plot(x,y,plotSymbol_str)
If I write out the string, it works fine. Why am I getting the error?

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 6 Mai 2014
Hi Ryan - I think that the problem is what you have said above - when you write out the string, it works fine. This string is a 1x26 char array, and it is this string that is being passed to the plot function not three individual strings separated by commas. The plot function allows for a variable number of inputs and while looping these inputs, it (probably) makes a decision on what to do with based on type. The third input to this function is an array of characters, and so it tries to match this character array (string) with any number of the expected ones ('MarkerSize','Color', etc.) but it can't…and so the error. (I get the same error message if i try plot(x,y,'geoff');.
So what you can do, is to create a command string and then evaluate it using eval. Please try the following:
% build the command string, concatenating the plot cmd, inputs, and colour choices
cmdstr = ['plot(x,y,' plotSymbol_str ')'];
% evaluate the command
eval(cmdstr);
You can then print the cmdstr and see what it looks like before you evaluate it:
cmdstr =
plot(x,y,'ro','MarkerFaceColor','b')
(Note that I changed the colours from white (w) to red and blue.)
Geoff
  1 Kommentar
MOLLAH KHOKON ALI
MOLLAH KHOKON ALI am 14 Aug. 2017
Problem: plot(EbNodB,log10(MQAM),char(colors(index)),'linewidth',1.5); Matlab shows an error for last loop of the program but this line shows no error to other loop of the same program through this line. But why?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by