Appdesigner create loop for drop down Items
显示 更早的评论
Hello,
I am using app designer to import data from a csv file an plot curves, based on the data from the file, in UIAxes. I'd like to implemet the function to change the colour of each curve. Therfore, I use a drop down field, filled with 8 different colours. These colours are defined in the private properties area (RGB values).
LightBlue = [0.3010 0.7450 0.9330];
DarkBlue = [0 0.4470 0.7410];
LightRed = [0.8500 0.3250 0.0980];
DarkRed = [0.6350 0.0780 0.1840];
Yellow = [0.9290 0.6940 0.1250];
Purple = [0.4940 0.1840 0.5560];
Green = [0.4660 0.6740 0.1880];
Black = [0 0 0];
After changing the dropdownfield-value, the user has to confirm his changes. To use a short code, I want to create a while-loop:
A = [app.ColourDropDown_1.Value app.ColourDropDown_2.Value app.ColourDropDown_3.Value app.ColourDropDown_4.Value app.ColourDropDown_5.Value app.ColourDropDown_6.Value app.ColourDropDown_7.Value app.ColourDropDown_7.Value];
B = [app.ColourCurve1 app.ColourCurve2 app.ColourCurve3 app.ColourCurve4 app.ColourCurve5 app.ColourCurve6 app.ColourCurve7 app.ColourCurve8];
C = 1;
while C<9
switch A(1,C)
case 'Light blue'
B(1,C) = app.LightBlue;
case 'Dark blue'
B(1,C) = app.DarkBlue;
case 'Light Red'
B(1,C) = app.LightRed;
case 'Dark Red'
B(1,C) = app.DarkRed;
case 'Yellow'
B(1,C) = app.Yellow;
case 'Purple'
B(1,C) = app.Purple;
case 'Green'
B(1,C) = app.Green;
case 'Black'
B(1,C) = app.Black;
end
C = C+1;
end
In the first iteration, the code should take the first value of matrix A (drop down field value). Then, it should take the first value from matrix B and allocate the colour-value.
Does anyone know a way to do that? I know the problem in my code, but is there another way than do the switch-case code for every chanel?
Thank you very much!
1 个评论
Mario Malic
2021-1-25
编辑:Mario Malic
2021-1-25
Table is the better way to store the colors and RGB values.
You can also consider line properties, most of these colors (if not all are available without RGB values - see line colors).
What's the purpose of having so many dropdown menus, you'll have to copy paste your callbacks plenty of times (which is not an issue), would it be acceptable for you if you'd have two dropdown menus with button to apply the color to selected line?
Do you have confirm button for every single line? From the description I can guess that you have 7 dropdowns for lines, and each of the dropdown consists of 8 colors, is this correct? Picture would be good as well. Where do you have apply button?
Will edit this bottom part tomorrow:
Your callback should be similar to this
function Dropdownvaluechanged(Source, Event)
% get the values on the both dropdowns
ddValue = Source.Value; % Gets the selected
ddRow = find(strcmpi(ddValue,Source.Items)) % Gets the row index of selected color
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!