Field text- number

13 Ansichten (letzte 30 Tage)
john
john am 14 Mär. 2012
Hi,
if I write integer number like 4 into field text, thens it is ok.
But when I write floating number like 4.5 into field text, then write error...
How can I do this?
Thanks
  2 Kommentare
Aldin
Aldin am 14 Mär. 2012
Do you work in MATLAB GUI?
Aldin
Aldin am 14 Mär. 2012
I don't know but i quess this is what you want:
set(handles.edit1,'String',num2str(4.5));

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Aldin
Aldin am 14 Mär. 2012
I have tested my code:
set(handles.edit1,'String',num2str(4.5));
It's correct.
  25 Kommentare
Aldin
Aldin am 20 Mär. 2012
Here is on maybe better solution: use *find* function.
For example if you have string like this:
>>string = '453,45434';
you can use *find* function you have to check if there in string exist comma: find(string==',') the result will be 4.
Now, if you have string like this: >>string = '4534434' (without comma) the result for _find(string==',')_ will be Empty matrix: 1-by-0. I hope my advice will be helpful
john
john am 20 Mär. 2012
Great idea, find(string==',') is very helpfull, thank yuo again

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by