Set color of Graph with uisetcolor
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Voss
2022-12-28
I guess I was confused because the error was in FarbeAuswhlenButtonPushed, but you shared the code for farbauswahl.
采纳的回答
Voss
2022-12-28
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 个评论
Voss
2022-12-29
编辑:Voss
2022-12-29
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Labels and Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!