필터 지우기
필터 지우기

How to visualise a dynamic array

조회 수: 2 (최근 30일)
Izuru
Izuru 2015년 5월 9일
댓글: Izuru 2015년 5월 10일
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
Izuru
Izuru 2015년 5월 10일
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 2015년 5월 10일
Sorry here's the screenshot

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 5월 10일
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.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by