Clear Filters
Clear Filters

How to export different string and numberic matrix to a file

1 view (last 30 days)
I wonder how to export string and numberic matrix (listed below) to a file. For example,
A={'cell';'gene';'protein';'DNA';'RNA'};
B={'cycle';'regulation';'structure';'replication';'editing'};
C=[1;2;3;4;5];
>> [A,B]
ans =
'cell' 'cycle'
'gene' 'regulation'
'protein' 'structure'
'DNA' 'replication'
'RNA' 'editing'
Now I want to make things like following format and export it but fails, help! Thanks for your time!
'cell' 'cycle' 1
'gene' 'regulation' 2
'protein' 'structure' 3
'DNA' 'replication' 4
'RNA' 'editing' 5

Accepted Answer

Jan
Jan on 4 Nov 2011
You did not explain how the file should look like. If you want a binary file to read it later in Matlab, use SAVE. For a text file with tabs as separators:
A = {'cell';'gene';'protein';'DNA';'RNA'};
B = {'cycle';'regulation';'structure';'replication';'editing'};
C = [1;2;3;4;5];
CC = num2cell(C, 2);
Data = transpose(cat(2, A, B, CC));
FID = fopen('FileName.txt', 'w');
if FID == -1, error('Cannot open file'); end
fprintf(FID, '%s\t%s\t%d\t\n', Data{:});
fclose(FID);
If you want something else, explaining the details is required.

More Answers (0)

Categories

Find more on Genomics and Next Generation Sequencing 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!