필터 지우기
필터 지우기

Set color of Graph with uisetcolor

조회 수: 6 (최근 30일)
Frank
Frank 2022년 12월 27일
댓글: Frank 2022년 12월 29일
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