Textscan reading file and surrounding text with single quotes
Ältere Kommentare anzeigen
I've realized that, in the simple function I'm trying to write, textscan appears to be reading in the text and surrounding it with single quotes. Here's what I mean:
Test file contents: ABCCBDXYZABCZZ
MATLAB commands:
fileID=fopen(FILENAME); str=textscan(fileID,'%s');
The result of this is a 1x1 cell, as expected, however the contents of the cell are: 'ABCCBDXYZABCZZ' instead of ABCCBDXYZABCZZ
This is proving to be an issue because accessing the cell contennts with "string = str{1}" only returns a cell, instead of an actual string- so I can't do any string operations on it. Is this intended behavior?
When I manually create a cell with the following:
cell_test = {'ABCDEF'};
the workspace shows the variable is a 1x1 cell, but the contents of the cell are ABCDEF without the single quotes, so if I do
string_test = cell_test{1}
it sets the actual string to that variable, instead of the string surrounded by single quotes, which is treated as another cell.
I can't find this issue anywhere else- it's possible that I've looked in the wrong place, but all the results are about not accessing the cell contents properly, which I don't believe I'm suffering from.
Akzeptierte Antwort
Weitere Antworten (1)
Azzi Abdelmalek
am 1 Sep. 2013
a={'abcd'}
disp(a)
disp(a{1})
what is the problem with that?
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!