Set color of Graph with uisetcolor
조회 수: 6 (최근 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!