Single quotes around dataset elements in 2017a?

조회 수: 1 (최근 30일)
Chuck
Chuck 2017년 6월 14일
댓글: Walter Roberson 2017년 6월 14일
In MATLAB 2017a, when I load a dataset, say, cities.mat, all the city names come with single quotes around them, as shown in the attached file. When I call, say, the 5th element, it returns the city name with the quotation marks. Moreover, there is no way of getting rid of them through indexing.
When I run the same dataset in 2014a, for example, the quotes are not there. What am I doing wrong?

답변 (2개)

Walter Roberson
Walter Roberson 2017년 6월 14일
Those quotation marks are not present in the input: they are part of the display. You would see the same thing if you went to the MATLAB command prompt and typed
'A'
Because are only part of the display representation you do not need to do anything about them unless you are dealing with display representation matters -- in which case you could continue to use fprintf()

Chuck
Chuck 2017년 6월 14일
That is what I thought too. But it is not that (or I'm missing something). If you look at the attached photo, the city name in the command window is followed by a lot of spaces and then a quote. These spaces come from the city name with the longest name. So if you say those spaces don't matter, I think I got my answer. But they are really annoying.
  댓글 수: 3
Steven Lord
Steven Lord 2017년 6월 14일
If you're using release R2016b or later, you could use a string array to store your text data unpadded. If you're using an earlier release, instead of storing your text data as a char matrix you could store it as a cell array, each cell of which contains a char vector. Walter used this cellstr technique in constructing the char matrix containing 'hello' and 'sam'.
Walter Roberson
Walter Roberson 2017년 6월 14일
Note that string() applied to a char array will leave the individual results blank padded. You could
strtrim(string(YourCharArray))
or you could
string(cellstr(YourCharArray)))
On the other hand, string data shows up with "" instead of '' so you do not remove the problem of the delimiters showing up in the default output format.

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

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by