GUI Handles

1 view (last 30 days)
Justin
Justin on 20 May 2012
I am trying to make a while loop that will set a series of push buttons to an image.
function[dealerCard,y,v,cardArray, valueArray] = cardDeal(cardArray, valueArray)
cardNumber =0
dealerCard = 0
while(dealerCard <= 17 && cardNumber <= 5)
v = genvarname('dealerCard',who)
t = ceil(rand*length(valueArray));
eval([v '= t'])
z = valueArray(t)
y = cardArray{t};
valueArray(t)=[];
valueArray
cardNumber = cardNumber + 1
dealerCard = dealerCard + z
handles = guidata(gcf);
set(handles.v,'visible','on','CDATA',y);
end
I am trying to use the eval function to create a varible dealerCardX, where x is a number. Then I want to set the correct push button to v. I get this as an error
??? Reference to non-existent field 'v'.
Error in ==> cardDeal at 19 set(handles.v,'visible','on','CDATA',y)
Error in ==> Blackjack>playerHit_Callback at 301 [cardArray, valueArray]=cardDeal(cardArray,valueArray);
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> Blackjack at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)Blackjack('playerHit_Callback',hObject,eventdata,guidata(hObject))
What am I doing wrong?
Thanks!

Answers (1)

Image Analyst
Image Analyst on 20 May 2012
I see you're using GUIDE because you're using the "handles" structure, and other reasons. First of all, you don't need to use evaL() AT ALL. I write GUIs all the time and I never ever use eval. Secondly, for your code to work you'd have to have some kind of control on your GUI that has a "Tag" property that you've called "v". Do you have that? Apparently not. It looks like you simply want to display some image so why don't you just call image or imshow:
imshow(y, 'Parent', handles.axes1); % Display image "y" in axes "axes1"
  2 Comments
Justin
Justin on 20 May 2012
I am using eval to create 5 variables (dealerCard1 - dealerCard5). The variable v is equal to dealerCardX. I will try your solution and modify it a little. Thanks for your input!
Walter Roberson
Walter Roberson on 21 May 2012
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

Sign in to comment.

Categories

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

Products

Community Treasure Hunt

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

Start Hunting!