How can i write a string row ( not English ) from excel to notepad or wordpad. Is it possible in Matlab?
I have attached a sample excel sheet

8 commentaires

Stephen23
Stephen23 le 30 Mar 2021
"How can i write a string row ( not English ) from excel to notepad or wordpad. Is it possible in Matlab?"
No: both notepad and wordpad are compiled binary applications, which cannot be "written to". Unless, of course, you want to destroy your application so that it cannot run anymore.
Or did you actually want to ask if you could write to a text file, which is a standard and very common file type (and which exists completely independently of any specific application)?
Elysi Cochin
Elysi Cochin le 30 Mar 2021
ya, i wanted to write it to a text file. I tried the below code, but what got printed was some symbols. How can i write the string (in the excel sheet) to a text file
Stephen23
Stephen23 le 30 Mar 2021
Modifié(e) : Stephen23 le 30 Mar 2021
"I tried the below code, but what got printed was some symbols."
Symbols is exactly what your file contains. The only two non-empty cells are these two:
These are the 30th and 31st letters of the Malayalam alphabet. I even went to the effort of checking them inside the XLSX file, here they are saved inside sharedStrings.xml:
Lets try Chris LaPierre's code and see what happens:
tbl = readtable("Book1.xlsx",'ReadVariableNames',false,"TextType","string");
writetable(tbl, "Book1.txt","WriteVariableNames",false,"Delimiter","\t");
str = fileread( "Book1.txt")
str =
'പ ത '
So far everything seems to be working exactly as expected. What specific problem do you have?
Note that some earlier MATLAB versions had only limited Unicode support: what MATLAB version are you using?
Elysi Cochin
Elysi Cochin le 30 Mar 2021
Modifié(e) : Elysi Cochin le 30 Mar 2021
Sir will this work for Matlab 2018a? I'm not getting the output
Two arrows (-> ->) are getting displayed in the text file for me
How can i resolve it?
Stephen23
Stephen23 le 30 Mar 2021
"Two arrows (-> ->) are getting displayed in the text file for me"
What application (i.e. text editor) are you using to look at this file?
"What application (i.e. text editor) are you using to look at this file?"
notepad
When i use the below statement after writing to txt file,
str = fileread( "Book1.txt")
the output in command window, i get is
str =
'
'
Stephen23
Stephen23 le 30 Mar 2021
I suspect that R2018a is unable to handle all Unicode correctly, but I have no way to check this. Perhaps Chris LaPierre can help further on clarifying this.
As an aside, I strongly recommend that you use a robust text editor, for example Notepad++.
Elysi Cochin
Elysi Cochin le 30 Mar 2021
Thank you sir for your suggestions

Connectez-vous pour commenter.

 Réponse acceptée

Cris LaPierre
Cris LaPierre le 30 Mar 2021

1 vote

5 commentaires

Elysi Cochin
Elysi Cochin le 30 Mar 2021
Modifié(e) : Elysi Cochin le 30 Mar 2021
ya, i read the excel sheet, and tried writing it to notepad, but it showed error,
Error using fprintf
Function is not defined for 'cell' inputs.
so i converted cell2mat and tried writing it to notepad
but what display was some sort of symbols
Below is the code i used,
[num, str, raw] = xlsread('Book1.xlsx');
fid = fopen('out.txt', 'wt');
fprintf(fid, '%s', cell2mat(raw));
fclose(fid);
Cris LaPierre
Cris LaPierre le 30 Mar 2021
Modifié(e) : Cris LaPierre le 30 Mar 2021
Try using readtable and writetable (see the links I already shared). They are preferred in this scenario.
d=readtable("Book1.xlsx",'ReadVariableNames',false,"TextType","string")
writetable(d,"Book1.txt","WriteVariableNames",false,"Delimiter","\t")
Elysi Cochin
Elysi Cochin le 30 Mar 2021
Sir will this work for Matlab 2018a? I'm not getting the output
Cris LaPierre
Cris LaPierre le 30 Mar 2021
Modifié(e) : Cris LaPierre le 30 Mar 2021
Doesn't sound like it. You hadn't indicated what version of MATLAB you were using, so I used my version, which is R2021a.
You may need to specify the encoding. Try using this for your write command.
writetable(d,"Book1.txt","WriteVariableNames",false,"Delimiter","\t",'Encoding','UTF-8')
For more details, see the "Write Foreign-Language Characters to Text Files" section of the R2018a writetable documentation.
Elysi Cochin
Elysi Cochin le 30 Mar 2021
Great Sir, thank you so much. Thanks a lot, now it works perfectly

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by