Changing the brush color using a color picker - different format
5 views (last 30 days)
Show older comments
whats the best way to convert the numbers in val
val =[1 1 0] % From color picker
To the format required here:
marker.FaceColorData=uint8(255*[1;0;0;1]); %Brush color, 4th digit is alpha Alpha=0.3 => 70% transparent red
thanks
(https://undocumentedmatlab.com/articles/hidden-hg2-plot-functionality)
0 Comments
Accepted Answer
dpb
on 14 Jan 2026
Edited: dpb
on 14 Jan 2026
Depends just slightly on whether you want to be able to set the alpha value other than the default 1...this is a good application for an anonymous function.
val2Face=@(v,a)uint8(255*[v(:);a]); % anonymous function to include alpha
val =[1 1 0]; % From color picker
alpha=0.7; % example alpha
cvec=val2Face(val,alpha)
If don't care about alpha, just omit it from the argument list and append the 1 in its place...
val2Face=@(v)uint8(255*[v(:);1]); % anonymous function with full strength
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!