Greta Stein
Greta Stein

Reputation: 75

How to convert string variables into TXT file without the appearance of the additional brackets in matlab?

I have (1 x 1 cell) with just one variable: TEXT1 = 'I am Text';

I wanted to use the following command to attempt a cell to txt file conversion:

writecell(TEXT1, 'Testdocument.txt');

However one I open up the Txt file itself I get some additional " " quote:

"I am text"

this is quite unusable in these line further as a makro. So i would like to know if there is a better command without those " " quote?

Upvotes: 0

Views: 123

Answers (1)

Thomas Sablik
Thomas Sablik

Reputation: 16447

"abc" is a string. 'abc' is a character array: Characters and Strings

You can convert a character array to a string with

string('abc') % "abc"

and a string to a character array with

char("abc") % 'abc'

TEXT1 = 'I am Text'; creates a char array. You can't use

writecell(TEXT1, 'Testdocument.txt');

with a char array. You can use

TEXT1 = 'I am Text';
writematrix(TEXT1, 'Testdocument.txt');

or

TEXT1 = 'I am Text';
writecell({TEXT1}, 'Testdocument.txt');

or

TEXT1 = {'I am Text'};
writecell(TEXT1, 'Testdocument.txt');

All versions create a text document without double quotes (" "):

I am Text

Upvotes: 3

Related Questions