How to visualise a dynamic array

1 view (last 30 days)
Izuru
Izuru on 9 May 2015
Commented: Izuru on 10 May 2015
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 Comments
Izuru
Izuru on 10 May 2015
Sorry I'm quite new to using matlab so my knowledge of syntax is quite limited.
Right now I have an array that records the values of the pushbutton.
I was thinking of using a for loop to go through the array and according to what number i.e 1, 2, 3, 4.. Set the colour in an edit textbox.Except I don't know how to progress to the next textbox.
Why did I use this? Because I wanted to keep it simple and that's what I knew at the time. Edit textbox is just to show colour only.
I've attached an image to the post on what i'm talking about.
Izuru
Izuru on 10 May 2015
Sorry here's the screenshot

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 10 May 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.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!