User defined color/linetype property
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Geoff Hayes
2014 年 5 月 6 日
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 件のコメント
MOLLAH KHOKON ALI
2017 年 8 月 14 日
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?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!