필터 지우기
필터 지우기

String Character mixup on data types

조회 수: 5 (최근 30일)
Karl
Karl 2015년 3월 8일
댓글: Geoff Hayes 2015년 3월 10일
Hey all, so I used sprintf to create a char. When I look at the workspace at it's class it shows as character however the value is 1x48 char. When I copy the output of that same item and set test= 'text' I see a class of character however the value is 'text' or 'text... (for longer strings).
Why are these not the same? What extremely simple thing am I forgetting in my tired state?
Thanks!
Can provide more input if needed!
  댓글 수: 7
Karl
Karl 2015년 3월 9일
Unsure how to check if a character type is a string. The closest I've found is ischar was true for both. Whos shows them as a 1x7 and 1x10 char.
Is there another command I'm not thinking of to use to check?
Geoff Hayes
Geoff Hayes 2015년 3월 10일
Karl - ischar is sufficient as is using class. What happens if you try the following to narrow down the problem
infoline1 = sprintf('%s',header.date);
infoline2 = sprintf('%s %s ',header.date,header.ExperimentTimeLocal);
infoline3 = infoline = sprintf('%s %s%dnm ',header.date,header.ExperimentTimeLocal,header.SpecCenterWlNm);
Do all produce reasonable strings? I can't help but wonder if there is a problem with one of your inputs (not a string, not an integer, etc.).

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

답변 (1개)

Jan
Jan 2015년 3월 8일
The code is correct in both cases. It is only the display in the command window which appears under certain conditions in the abbreviated form. The contents of the variable is a char string in both cases, so everything is fine.
If you post the code, which reproduces the problem, it would be easy to demonstrate what's going on.
  댓글 수: 1
Guillaume
Guillaume 2015년 3월 8일
And this is not particular to strings. For short vectors of anything, matlab displays the content of the vectors in the workspace browser. For longer vectors, it just displays their size.

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by