필터 지우기
필터 지우기

NaN when I type "known" variables (like pi, etc) in an editable uitable

조회 수: 2 (최근 30일)
Marco
Marco 2013년 1월 21일
Hi,
I have an uitable with 2 columns and its ColumnFormat are char and numeric; the numeric column is editable.
When I type pi or pi/2 it returns 'NaN' where I type.
Matlab Help suggests to use CellEditCallback command, but I don't understand how I shoud use it and how can it solves my problem.
Thanks

채택된 답변

Jan
Jan 2013년 1월 21일
"Numeric" means numeric, such as 1.23 or -1e-16, while pi/2 has to be interpreted. The CellEditcallback (you can use this term to let Google find more details for you) can call eval() to evaulate this expression. But then a small test would be fine to control that no mad user tries to input '!format C:', because even this command would be evaulated (of course not successfully, but I do not post dangerous commands here). A minimal test is to exclude all strings, which contain '!', 'dos' and 'system', but even the local variables of the CellEditCallback function can be overwritten, 'error' let the program stop, 'quit' closes Matlab etc.
Perhaps converting the string to a sym expression at first is more secure.
  댓글 수: 1
Marco
Marco 2013년 1월 21일
I thought CellEditCallback was a function can I use when I finished to type. For example to convert pi/2-string into its numeric value.

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 21일
If you want to type pi/2, then make your column format char
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 21일
If you want to use pi/2 as numeric , just use the function str2num
Marco
Marco 2013년 1월 21일
where should I use it ?

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

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by