Trouble with plotting different symbols and colors indexed by a matrix in an m-file. How do I make the m-file handle color and symbol strings that work on command line?
3 views (last 30 days)
Show older comments
I have an m-file where I am trying to dynamically plot different indexed parts of a data set with different symbols and colors. The idea is to plot blank contamination data performed by different analysts and being able to see what analysts plot out where in the contamination field so I can adapt my training to analysts who repeatedly register a high blank. The data set is constantly changing, so I have an m-file that reads the data file and creates a Color Array and a Symbol Array based on the number of different analysts in a single data set. These arrays are of different sizes so that color and symbol pairs will not reproducible for quite some time.
I tested some code on the command line, and it worked. However, in the m-file it doesn't work. I get the error message:
ans =
'v'
Error using matlab.graphics.chart.primitive.Line/set
While setting the 'Marker' property of 'Line':
Invalid enum value. Use one of these values: '+' | 'o' | '*' | '.' | 'x' | 'square' | 'diamond' | 'v'
| '^' | '>' | '<' | 'pentagram' | 'hexagram' | 'none'.
Error in LiveBlankDeterm (line 168)
set(ss,'Marker',symbols{k(1)});
The "answer: 'v'" line is a probe I put in the code to see exactly what the the m-file is trying to insert into the plot command line. With or without the single quotes, this error message is generated, but you can see that the string ('v' or v, in this case, is the first symbol in the symbol array) fails to register in the plot command. Furthermore, if I tweak the order and specify the color array first, before the symbol array, it generates the error message the color must be in numeric form (3-element vector, 0-1 for each element).
The m-file code that is generating this error looks like this:
hold on
for nn=1:max(abbcounter)
k=find(namecode==nn);
symbols{k(1)}
ss=plot(D(min(k):max(k),1)/1000,D(min(k):max(k),2));
set(ss,'Marker',symbols{k(1)});
end
From the "set" line, I can add or alternate the color array. The namecode is simply an integer in the data corresponding to the analysts' abbreviations used to generate the legend.
In command line, similarly written code (in this case not using the set command, but addressing the linespec properties directly) like -
plot(nn,b(min(k):max(k)),'Marker',symbols{nn})
works just fine. But not in the m-file.
Any ideas on how I can improve this code to make it work - from a modest tweak to a complete change in program flow?
Thanks, Brad
12 Comments
dpb
on 25 Sep 2017
I suppose this is a result of the new string class? Being able to tell what you had at the command line without other machinations was always a real boon to debugging in particular.
Walter Roberson
on 25 Sep 2017
The decorations were generally added to in R2017b, giving more information than before to emphasize class, but sometimes in a "too much information" way.
>> n_raw = {
0.023391
0.31236
0.0073958
0.6252
14.158
-14.159
0.046701
0.095463 }
n_raw =
8×1 cell array
{[ 0.023391]}
{[ 0.31236]}
{[0.0073958]}
{[ 0.6252]}
{[ 14.158]}
{[ -14.159]}
{[ 0.046701]}
{[ 0.095463]}
>> n_raw{1,1} = {1}; n_raw{1,2} = 'hello'; n_raw{2,1} = [1 2]
n_raw =
8×2 cell array
{1×1 cell } {'hello' }
{1×2 double } {0×0 double}
{[0.0073958]} {0×0 double}
{[ 0.6252]} {0×0 double}
{[ 14.158]} {0×0 double}
{[ -14.159]} {0×0 double}
{[ 0.046701]} {0×0 double}
{[ 0.095463]} {0×0 double}
In other words there is no point in using the [] within the {} of each cell because it is not possible for anything more than a scalar (or character vector, or single string) to be displayed there. Adding the {} decoration at every point implies that there is the potential for multiple items to be displayed inside the {}, which is not the case.
... To which Mathworks replied that this new decoration does not apply if you specifically ask to disp() a value.
Answers (0)
See Also
Categories
Find more on Legend 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!