Form of number

조회 수: 3 (최근 30일)
john
john 2012년 6월 11일
Hi,
if I enter into edit text a number 6.67e-2, then in uitable I got this number in form like 667/10000.
So is possible to show this number in form of 6.67e-2?
Thanks for help
  댓글 수: 1
john
john 2012년 6월 11일
At firts I convert number 6.67e-2 into cell UserData.matrix(3,2)=num2cell(str2double(get(handles.edit7,'String')));.
.
.
then in other part of program I use data(i,j)=sym(UserData.matrix{i,j}); for print number in uitable

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

채택된 답변

Matt Tearle
Matt Tearle 2012년 6월 11일
It looks as if the table's ColumnFormat property is set to rat, but that would require setting the property. It looks like you're using GUIDE, so open up the Property Inspector on the uitable and see what the ColumnFormat property is. Set it to an appropriate numeric format.
EDIT TO ADD: sorry, didn't read your initial comment carefully enough. Um... why are you converting to a sym to print the number? If you need a symbolic variable somewhere, extract from UserData.matrix and convert there. Rational display is standard for symbolic variables, so the behavior you're seeing makes perfect sense.
EDIT #2: OK, so it sounds like the actual problem you're trying to solve is: "can I set the formatting so that numbers and strings are both justified the same (either left or right)?" Yes. Just, treat everything as a string:
figure
h = uitable;
set(h,'ColumnFormat',{'char', 'char'},'Data',{pi,'hello';'42',6.67e-2})
Don't use sym unless you are actually doing symbolic calculations. It is not a fundamental data type in MATLAB, so these conversions aren't really doing much other than slowing down your code.
  댓글 수: 7
john
john 2012년 6월 12일
Yes, I am using a symbolic and also numerical calculation.
Now everything works ok.
For load number in form 4.8893e-4 is used UserData.matrix(3,2)=num2cell((str2double(get(handles.edit7,'String'))));
but function vpa works not correctly :(.
thanks for 'ColumnFormat',{'char', 'char'}....it helped
Walter Roberson
Walter Roberson 2012년 6월 12일
The num2cell is unnecessary overhead. Use
UserData.matrix{3,2} = str2double(get(handles.edit7,'String'));
Most of the time you do not need to vpa() a numeric value. There are good reasons to use vpa(), but when you are interfacing with MATLAB itself you are more likely to use double() to convert a symbolic expression to a double precision number.

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by