이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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
2012년 6월 11일
1 개 추천
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
2012년 6월 11일
Hi, ColumnFormat property doesn't help.
here is problem........if I use this command sym(UserData.matrix{4,2}) I get 667/10000.
john
2012년 6월 11일
or other question. I have cell matrix with numbers and strings. I insert numbers and strings into cell matrix with command UserData.matrix(3,2)=num2cell(str2double(get(handles.edit7,'String')));...for numbers and UserData.matrix(3,1)=num2cell(sym(get(handles.edit5,'string')));...for strings.
.
.
and I need to show numbers and strings in uitable...so how can I do that?
Walter Roberson
2012년 6월 11일
I really don't know why you keep using sym() all over the place instead of just when you need to construct a symbolic formula. For example, just use
UserData.matrix{3,1}=get(handles.edit5,'string');
Anyhow, if you must use sym, add the argument 'd' to the sym() call:
UserData.matrix(3,1)=num2cell(sym(get(handles.edit5,'string'), 'd'));
john
2012년 6월 11일
I use sym because I need UserData.matrix(3,1)=num2cell(-1*sym(get(handles.edit5,'string')));.
..
.
numerical values in uitable are centered to the right side, and texts are centered to the left side....can I centered numerical values to the right side ?....number 6.4535e-3 already in uitable, but in the right side, and others strings are centered to the left....so I looks like lite bit chaos....so is possible all to centered to the left or all to the right side?
Walter Roberson
2012년 6월 12일
Why does UserData.matrix(3,1) have to be a symbol? Why can you not use
UserData.matrix{3,1} = [ '-(' get(handles.edit5, 'String') ')' ];
That is, just put in the negative sign textually, and not convert to sym until the step where you are ready to do a symbolic calculation?
There is no way to change the centering of numeric values in uitable(). You can change the centering of string values by changing the number of spaces in the string (but watch out for proportional fonts.)
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
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개)
카테고리
도움말 센터 및 File Exchange에서 Operations on Strings에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
