fprintf to write string to csv
5 views (last 30 days)
Show older comments
Hi,
I am trying to write some strings to a csv file using the fprintf. It's working good for some strings. However, for strings with commas, the code see the str_commas as a delimiter. Any suggestion. Thanks in advance.
eg. fprintf(WriteCellFile,'%s,%s,%s,%s,%s\r\n', Toxin,'k_fit','m_fit','Area','Curve')
%%Toxin is the string with commas.
Vig
0 Comments
Accepted Answer
Image Analyst
on 5 Jun 2012
You have to change the commas to something else (like "_comma_") if you want it to be a CSV file as you'd expect. You can use the strrep() function for this:
Toxin2 = strrep(Toxin, ',', '_comma_');
then write out Toxin2 instead of Toxin. Then at some point, you'll probably read in your csv back in and you'll need to undo that string replacement to decode it back to what it was when you started (i.e., return again to a normal comma):
originalString = strrep(readInString, '_comma_', ',');
Now you're ready to use the string again with the comma embedded in it.
More Answers (0)
See Also
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!