フィルターのクリア

How can I save a word e.g. 'apple' in a text file, without matlab separating every letter with a comma?

1 回表示 (過去 30 日間)
So i am trying to save a text, into a txt file. e.g. i like apples, not bananas.
BUt the txt file has every single letter separated by commas. How can I join them togetehr when read by another function ? or not save it like that, but as a text?

採用された回答

dpb
dpb 2019 年 4 月 14 日
You undoubtedly use csvwrite or similar to write a character array -- internally a char() array is just that--an array of numbers that happen to be have the display characteristics of the character represented instead of the number underlying it--but csvwrite doesn't know that; it just writes the elements of the array as individual numbers. When retrieved, those numeric values are still those of the character so they are displayed correctly, but now they are individual array elements, not the array...it's why you have to use 2D addressing on a char() string to get the whole string, not just the first character.
>> csvwrite('apple.txt','apple') % mimic what you (apparently) did...
>> type apple.txt % symptom you saw...
a,p,p,l,e
fid=fopen('apple.txt','w'); % open a file handle with write permission...
fprintf(fid,'%s\n','apple'); % write a record w/ \n
fid=fclose(fid); % close the file
>> type apple.txt % now see what it contains
apple
>>
It's somewhat of a pain -- the Matlab i/o functions have progressed remarkably for input of text files of various forms; unfortunately, the output side is "not so much" as yet.
There are two higher-level routines writetable and xlswrite that can do some nice things, but they also have their limitations as to what they can do...

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by