How to visualise a dynamic array
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
My problem is as follows. I have four pushbuttons made in the GUI which are blue, green, orange and black I also created 12 edit boxes in a row in order to change it's background colour.
So everytime I click one of the four push buttons I store it's value in an array. Reason being is that I want to create a colour pattern that goes up to 12.
For example: I click blue = 1, green = 2, blue = 1, orange = 3 etc which creates the array;
[1 2 1 3 ... up to 12 elements ]
I want to dynamically update and display the colours by changing the colours of the edit boxes. So everytime I press a pushbutton the corresponding editbox (out of the 12) will be coloured.. Any suggestions?
4 Commenti
Risposte (1)
Walter Roberson
il 10 Mag 2015
function testit
colorlist = [0 0 1; 0 1 0; 1 .4 0; 0 0 0]; %RGB table. blue, green, orange; black
NextEditBoxNum = 1; %shared variable!!
color_record = zeros(1,12); %shared variable!!
pb = zeros(1,12); %pushbuton handles
eb = zeros(1,12); %edit box handles %shared variable!!
function pb_callback(src, obj) %nested function!!
if NextEditBoxNum <= 12
this_colorid = get(src, 'UserData');
color_record(NextEditBoxNum) = this_colorid;
set(eb(NextEditBoxNum), 'BackgroundColor', colorlist(this_colorid, :) );
NextEditBoxNum = NextEditBoxNum + 1;
end
end
for K = 1 : 4
pb(K) = uicontrol('style', 'pushbutton', 'Position', [....], 'UserData', K, 'BackgroundColor', colorlist(K, :), 'Callback', @NextEditBoxNum );
end
for K = 1 : 12
eb(K) = uicontrol('Style', 'edit', 'Position', [....], 'BackgroundColor', [1 1 1]);
end
end
That is, you need something shared between the routines to tell you which is the next edit box to affect (that is, how many times a button has been pushed, and you need something shared that is keeping a record of which color was selected for each. The pushbutton callback figures out which color identifier it corresponds to, adds that to the list recorded so far, and sets the edit box to be the color corresponding to that color identifier.
I am not sure why you are using an edit box to hold the color selected -- are you expecting the user to be entering some text there? If you just want to hold a swath of the color, there are other uicontrol styles that are better suited.
0 Commenti
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!