Thread Subject:
get command of matlab GUI

Subject: get command of matlab GUI

From: amey patil

Date: 13 Apr, 2012 14:28:18

Message: 1 of 3

Hello,
I have a problem .I want to read data through a text box of GUI of matlab and this data happens to be in decimal and I want to convert into HEX data then I need to print that data in to text file in HEXADECIMAL format.
This i m doing as below
for get I m using following command tio read data from text box

X = get (hObject,'value');

then
i m reading this value and converting it in to hex by following command

X1 = dec2hex (X);

then i am writing it to text file by following code

fprintf (fid, '%d ',X);

after doing this i should see result in text file but I m not able to see hex codes intead I m getting "0" answers.

Where is the problem.

Subject: get command of matlab GUI

From: John Smith

Date: 26 Apr, 2012 14:03:07

Message: 2 of 3

"amey patil" <ameypatil28@yahoo.co.in> wrote in message <jm9d62$hg0$1@newscl01ah.mathworks.com>...
> Hello,
> I have a problem .I want to read data through a text box of GUI of matlab and this data happens to be in decimal and I want to convert into HEX data then I need to print that data in to text file in HEXADECIMAL format.
> This i m doing as below
> for get I m using following command tio read data from text box
>
> X = get (hObject,'value');
>
> then
> i m reading this value and converting it in to hex by following command
>
> X1 = dec2hex (X);
>
> then i am writing it to text file by following code
>
> fprintf (fid, '%d ',X);
>
> after doing this i should see result in text file but I m not able to see hex codes intead I m getting "0" answers.
>
> Where is the problem.

To get the number from your text box correctly, you need to do:
X = str2num(get (hObject,'String'));

Subject: get command of matlab GUI

From: ImageAnalyst

Date: 26 Apr, 2012 16:21:59

Message: 3 of 3

Try this instead:
X = str2num(get (hObject,'String')); % String, not value, then cast to
a numeric data type.
and then fix this second error:
fprintf (fid, '%d ',X1); % Not X, should be X1 which is the Hex.

Also, make sure X is correct, because I don't know that hObject is
correct. That would be the correct in the callback of the edit field,
but not if you were using it in the callback of a "Write to file"
button. In that case, you'd have to use the actual handle name of the
control, e.g. handles.editText1, rather than hObject because hObject
would refer to the button, not the edit text field.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us