User defined color/linetype property
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ryan
il 6 Mag 2014
Commentato: MOLLAH KHOKON ALI
il 14 Ago 2017
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?
0 Commenti
Risposta accettata
Geoff Hayes
il 6 Mag 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 Commento
MOLLAH KHOKON ALI
il 14 Ago 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?
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!