GUI - text instead of numbers

HI! Im making a program using the GUI. I wonder if it is possible to have an output consisting of text rather than number (that is to be in a static text button).
I am making a program that with three inputs can calculate what kind of girder you need in a construction. So that is why the output must consist of letters (e.g. HEA-140) and not only numbers. How do you do that?

Answers (2)

You could use a cell array that contains the girder names and properties. It finds the row of a cell array with working properties and outputs the name. E.g.
G = {'W12x40',17,30;'W28x220',60,90} %Example names and fictional properties
function testpj()
hf=figure;
h1 = uicontrol(hf,'Style','edit',...
'string','',...
'Position',[30 20 150 30]');
h2 = uicontrol(hf,'Style','edit',...
'string','',...
'Position',[30 90 150 30]);
h3 = uicontrol(hf,'Style','text',...
'string','',...
'Position',[200 20 150 30]);
h4 = uicontrol(hf,'Style','pushbutton',...
'string','DoTheMagic',...
'Position',[400 20 150 30],...
'callback',@DoTheMagic);
msgbox('Insert the numeric values on the two edit boxes, press the button')
function DoTheMagic(a,b)
v1=str2num(get(h1,'string'));
v2=str2num(get(h2,'string'));
v3=v1+v2; %do the calculation here
%replace the constraints by the ones you need
if (v3>=1 & v3<=5)
girder='HEA-140';
elseif (v3>5 & v3<=10)
girder='HEA-141';
elseif (v3>10 & v3<=20)
girder='HEA-142';
elseif (v3>=10 & v3<=50)
girder='HEA-143';
else
girder='Unknown';
end
set(h3,'string',girder) %put the response on the textbox
end
end
If you are using GUIDE, use the code inside my DoTheMagic function but replace h1,h2,h3 by handles.edit1,handles.edit3,handles.text3 or whatever your objects are called.

Categories

Asked:

on 8 Jun 2011

Community Treasure Hunt

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

Start Hunting!