Set color of Graph with uisetcolor
12 views (last 30 days)
Show older comments
Hi Guys,
I have a small Problem in Appdesigner. I got a DropDownMenu which where I can choose different Options for a Graph. Now I want that the user of the App can choose the colors for the different DropDown Options. I created a Tab in my app with a DropDown Menu with the same Options and Properties as the one for the Graph and now want that if you choose your Option you can open the Color Picker to choose your color.
So far:
function farbauswahl(app)
for i = app.R.(app.FarbauswahlDropDown.Value(3:14))
Farben(i,:)=uisetcolor;
end
end
This is my Error:
Error using matlab_projekt2_0/FarbeAuswhlenButtonPushed
Index exceeds the number of array elements. Index must not exceed 1.
I don´t really understand what the Error means, neither how to solve it.
Maybe I have the wrong approach?
Thank you
3 Comments
Voss
on 28 Dec 2022
I guess I was confused because the error was in FarbeAuswhlenButtonPushed, but you shared the code for farbauswahl.
Accepted Answer
Voss
on 28 Dec 2022
I'm not sure which dropdown menu should be linked to the color matrix, so I call it app.DropDown.
This assumes the color matrix app.meine_farben is already populated (otherwise you'll potentially get rows of zeros):
function FarbeAuswhlenButtonPushed(app, event)
new_color = uisetcolor();
if isequal(new_color,0) % User didn't pick a color
return
end
idx = find(strcmp(app.DropDown.Items,app.DropDown.Value),1);
app.meine_farben(idx,:) = new_color;
end
I'm also not sure how [0 0 5] is a color, or [3 0 1], etc. Usually RGB colors are between 0 and 1 in each channel (or between 0 and 255, etc., depending on the class). Are those on a 0 to 255 scale? If so they're all so close to [0 0 0] as to be basically indistinguishable from black.
14 Comments
Voss
on 29 Dec 2022
Edited: Voss
on 29 Dec 2022
Well, you have to make the colors take effect on the bars. The code you show, setting a bar's FaceColor to a row of app.meine_farben presumably works to set the bars' colors to the existing app.meine_farben, but when app.meine_farben changes, you have to do something to make that change take effect. So either (1) delete and re-create the bars whenever a color is selected, or (2) better, create the bars once and update their colors when a color is selected.
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps 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!