Borrar filtros
Borrar filtros

User defined color/linetype property

3 visualizaciones (últimos 30 días)
Ryan
Ryan el 6 de Mayo de 2014
Comentada: MOLLAH KHOKON ALI el 14 de Ag. de 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?

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 6 de Mayo de 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 comentario
MOLLAH KHOKON ALI
MOLLAH KHOKON ALI el 14 de Ag. de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by