edge colordata property attempts to set are inconsistent

1 view (last 30 days)
The following section of code works fine when I manually enter them one at a time on the command line, or run the m file with a stop at the set line, and then step past the line.
It doesn't work however if I simply let the m file run completely with a pause. What am I doing wrong?
figure('Position',[166 325 1205 755])
h = plot(gps(:,1),gps(:,2),'r');
spd = a(spdChan).Data(ind);
cmap = colormap;
cmapX = [min(spd):(max(spd) - min(spd))/(size(cmap,1)-1):max(spd)]';
tmp = interp1(cmapX,cmap,spd);
interpCmap = cast([255*tmp 255*ones(size(tmp,1),1)]','uint8');
set(h.Edge, 'ColorType','truecoloralpha', 'ColorBinding','interpolated', 'ColorData', interpCmap);
  5 Comments

Sign in to comment.

Accepted Answer

Kelly Kearney
Kelly Kearney on 15 Jul 2016
I've found that messing around with some of the undocumented properties of new graphics objects can be finicky, with properties resetting to their original values later, or failing to change when run in a script (as you're seeing). I recommend only resorting to this sort of hacking when you can't find any workarounds using the documented properties.
Luckily, there's an easy workaround for color-changing lines, and it eliminates the need to do the color interpolation manually: use a patch instead.
x = [0:.01:20];
y = [0:.01:10 9.99:-.01:0];
hln = patch([x NaN], [y NaN], [y NaN]);
set(hln, 'edgecolor', 'interp');
  2 Comments
Jeff
Jeff on 15 Jul 2016
Edited: Jeff on 15 Jul 2016
Thanks, I hadn't thought of that. I was also planning on using transparency as a crude 4th dimension. I'll have to research this more to see if I can also control that as well?
Walter Roberson
Walter Roberson on 15 Jul 2016
patches support EdgeAlpha and FaceVertexAlphaData properties

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!