Filter löschen
Filter löschen

How to export different string and numberic matrix to a file

1 Ansicht (letzte 30 Tage)
frewise
frewise am 4 Nov. 2011
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

Akzeptierte Antwort

Jan
Jan am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Genomics and Next Generation Sequencing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by