フィルターのクリア

How to write a cell array of mixed strings and integers into a text file?

7 ビュー (過去 30 日間)
chocho
chocho 2018 年 12 月 17 日
コメント済み: chocho 2018 年 12 月 17 日
Hello guys,
I have a cell array of 700 rows and 2 columns,
The first column have a mixed of strings and integer values like this:
'GALK1' 1
'ERCC2' 1
'PGD' 1
'PLK' 1
0 0
0 0
0 0
0 0
0 0
i write this code but the cells of column 1 didn't show that 0 and only strings , which type i can use that can detect both strings and integers for the same column?
[rowfile1,colfile1]=size(Stages_pathws_genes_counts);
fidefile1= fopen('Rec_Stages','wt');
fprintf(fidefile1, '%s\t%s\n','Stg1_genes','#Stg1_count');
for gfile1=1:size(Stages_pathws_genes_counts)
fprintf(fidefile1,'%s\t %d\t',Stages_pathws_genes_counts{gfile1,:});
fprintf(fidefile1,'\t');
fprintf(fidefile1,'\n');
end
fclose(fidefile1);
Can anyone plz suggest me ?
  2 件のコメント
madhan ravi
madhan ravi 2018 年 12 月 17 日
編集済み: madhan ravi 2018 年 12 月 17 日
Upload your text file
chocho
chocho 2018 年 12 月 17 日
@madhan ravi ok here it is

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2018 年 12 月 17 日
編集済み: Stephen23 2018 年 12 月 17 日
Where C is your cell array:
C = {'GALK1',1;'ERCC2',1;'PGD',1;'PLK',1;0,0;0,0;0,0;0,0;0,0};
D = cellfun(@num2str,C,'uni',0).';
[fid,msg] = fopen('temp0.txt','wt');
assert(fid>=3,msg)
fprintf(fid,'%s\t%s\n',D{:})
fclose(fid);
The file it creates is attached.
  4 件のコメント
Stephen23
Stephen23 2018 年 12 月 17 日
編集済み: Stephen23 2018 年 12 月 17 日
@chocho: check my edited answer. It uses your example cell array and writes a text file (attached to the answer). You did not describe the required file formatting and it is not completely clear from your code, so I guessed that you wanted the data in two columns.
chocho
chocho 2018 年 12 月 17 日
@Stephen Cobeldick Thanks a lot a lot a lot Stephen !

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2018 年 12 月 17 日
Let C be your cell array
fid = fopen('test.txt','w');
fprintf(fid,'%s\n',C{:});
fclose(fid);
  4 件のコメント
KSSV
KSSV 2018 年 12 月 17 日
If you don't want to write zero strings in column 1 of cells:
load('ret.mat') ;
C = Ret ;
fid = fopen('data.txt','w');
for i = 1:length(C)
fprintf(fid,'%s %f\n',C{i,1},C{i,2});
if C{i,1}==0
break
end
end
fclose(fid);
chocho
chocho 2018 年 12 月 17 日
編集済み: chocho 2018 年 12 月 17 日
No, i want to write everything strings and zeros as well

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by