How to export different string and numberic matrix to a file

1 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2011-11-4
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genomics and Next Generation Sequencing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by