Exporting matrices as text file

2 views (last 30 days)
Olu adroit
Olu adroit on 4 Feb 2015
Edited: dpb on 5 Feb 2015
Hi all, I have three matrices A = [ ‘Picked’], B = [‘P’] and C = [100]. I would like to export them as a single text file (.txt) which will look like this: Picked, P, 100 I have tried to use ‘csvwrite’ but I could only obtain P,i,c,k,e,d,P,100. Please could anyone help me with how to do this. Thanks in advance.

Accepted Answer

dpb on 4 Feb 2015
Edited: dpb on 5 Feb 2015
>> fprintf('%s,%s,%d\n',A,B,C)
Character strings are arrays of characters in Matlab so csvwrite treats each character as an array element (as you discovered). Use the string format specifier to put the array out as a single string as shown.

More Answers (0)


Find more on Characters and Strings 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!

Translated by