欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

matlab读写文件

程序员文章站 2022-04-01 08:45:24
...
TrainList=importdata('\\172.31.222.30\DataSet2\Flickr_30K\flickr30k-caption\trainTxt.txt');
fwrite=fopen('Flickr30k_train_txt.list','wt');
for i =1:29783  
    path=TrainList{i};
    fullpath=fullfile('\\172.31.222.30','Dataset2','Flickr_30K','Flickr30k-caption','dataset',path);
    fid=fopen(fullpath,'rt');
    content='';
    while feof(fid)~=1
        line=fgetl(fid);
        content=strcat(content,line);
    end
    fclose(fid);
    fprintf(fwrite,'%s\n',content);
end
fclose(fwrite);


----------------onehot-------------
load('test_lab.mat');
test_lab_462=zeros(462,10);
for i=1:462
    x=test_lab(i,1);
    test_lab_462(i,x)=1;
end
%dlmwrite('test_lab.txt', test_lab_462, 'delimiter', ' ','newline','unix') 
%dlmwrite('test_lab.txt', test_lab_462)

save('test_lab_462.mat','test_lab_462');
fid=fopen('test_lab.txt','w');
[b1 b2]=size(test_lab_462);
for i=1:b1
    for j=1:b2
       fprintf(fid,'%d ',test_lab_462(i,j));
    end
fprintf(fid,'\r\n');
end
fclose(fid);