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:
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 个评论
Frank
Frank 2022-12-28
No, "FarbeAuswhlenButtonPushed" is a button that opens the color picker. Which I can use now after writing
function FarbeAuswhlenButtonPushed(app, event)
uisetcolor(app.meine_farben);
But, question is how do I now link the different colors to the different values in my drop down menu?
I tried it like this:
b1 = bar(app.UIAxes,app.R.DatumUhrzeit,app.R.(app.EnergietrgerDropDown.Value));
for i = 1:1
b1(i).FaceColor = app.meine_farben(i,:);
end
and the property "meine_farben" is just a color matrix
app.meine_farben = [0 0 5
1 0 1
0 0 1
2 0 0
2 0 1
0 0 2
3 0 0
3 0 1
0 0 3
4 0 0
4 0 1
0 0 4];
I think I lack communication between the different parts? The thought was to "link" the first row of the color matrix to the first option in the DropDown Menu. And than being able to change color via the button "FarbeAuswhlenButtonPushed", opening the color picker.
Voss
Voss 2022-12-28
I guess I was confused because the error was in FarbeAuswhlenButtonPushed, but you shared the code for farbauswahl.

请先登录,再进行评论。

采纳的回答

Voss
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
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.
Frank
Frank 2022-12-29
Ok, thank you! :) I´ll let you know if it worked!
Thanks for taking the time, you really helped me out here!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by