string output in text-file without " " (quotation notes). MATLAB BUG? comma in string effects quotation notes in .txt-file
Mostrar comentarios más antiguos
Hi guys!
I noticed something strange in MATLAB. Maybe anybody knows this problem.
I would like to write a string-vector into a .txt-file.
If my string-vector contains a comma "," so my .txt.file begins with an quotation mark and end with one "....."
But i need a .txt-file without quotation marks, only with the strings, which maybe contains commas...
example 1 without comma in string and so without quotation marks in .txt-file:
Name1 = "Walter";
Gewicht1 = 55;
testvektor(1,1) = "Walter hat " + " / Hunger "+"";
testvektor(2,1) = "Gewicht" + ": " + Gewicht1;
fid = fopen('Textdatei.txt','wt');
writematrix(testvektor,'Textdatei.txt',"FileType","text")
fclose(fid);
Output example 1:
Walter hat / Hunger
Gewicht: 55
example 2 with comma in string and so with quotation marks in .txt-file:
Name1 = "Walter";
Gewicht1 = 55;
testvektor(1,1) = "Walter hat " + " / Hunger "+",";
testvektor(2,1) = "Gewicht" + ": " + Gewicht1;
fid = fopen('Textdatei.txt','wt');
writematrix(testvektor,'Textdatei.txt',"FileType","text")
fclose(fid);
Output example 2:
"Walter hat / Hunger "
"Gewicht: 55"
Thank you for helping guys!
Hope you know the issue!
Best regards,
Maxim
2 comentarios
Walter Roberson
el 12 de Mzo. de 2022
It is not advisable to fopen(), writematrix(), fclose(). writematrix() does not operate on a file identifier: it opens and closes the file as needed. The extra fopen() justs risks glitches, unnecessarily.
Maxim Kindsvater
el 13 de Mzo. de 2022
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!