matlab - how to dlmwrite a file from array -
how write cell below in text file(my_data.out)?
http_only = cell2mat(http_only) dlmwrite('my_data.out',http_only)
i error below:(i have tried solve still return me error)
here full code: want generate text file each of data store 'http_only' check meet word in split_url.
%data = importdata('data/url/training_url') data = importdata('data/url/testing_url') domain_url = regexp(data,'\w*://[^/]*','match','once') no_http_url = regexp(domain_url,'https?://(?:www\.)?(.*)','tokens','once'); no_http_url = vertcat(no_http_url{:}); split_url = regexp(no_http_url,'[:/.]*','split') [sizedata b] = size(split_url); = 1:100 a7_data = split_url{i}; data2=fopen(strcat('data\webpage_source\testing_data\',int2str(i),'.htm'),'r') chardata = fread(data2, '*char')'; %read text file , store data in chardata fclose(data2); img_only = regexp(chardata, '<img src.*?>', 'match'); %checking http_only = regexp(img_only, '"http.*?"', 'match'); http_only1 = horzcat(http_only{:}); fid = fopen('my_data.out',int2str(i),'w'); col = 1:numel(http_only1) fprintf(fid,'%s\n',http_only1{:,col}); end fclose(fid); feature7_data=(~cellfun('isempty', regexpi(chardata , a7_data, 'once'))) b7(i)=sum(feature7_data) end feature7(b7>=5)=-1; feature7(b7<5&b7>2)=0; feature7(b7<=2)=1; feature7'
write cell-by-cell using fprintf
-
fid = fopen('my_data.out','w'); col = 1:numel(http_only) fprintf(fid,'%s\n',http_only{:,col}); end fclose(fid);
edit 1: if input cell array of cell arrays, use code instead.
code
http_only1 = horzcat(http_only{:}); fid = fopen('my_data.out','w'); col = 1:numel(http_only1) fprintf(fid,'%s\n',http_only1{:,col}); end fclose(fid);
edit 2: number of inputs stored separate files, use demo -
data1 = {{'[]'} {'"http://google.com"'} {'"http://yahoo.com'}}; data2 = {{'[]'} {'"http://overflow.com"'} {'"http://meta.exchange.com'}}; data = cat(1,data1,data2); k = 1:size(data,1) data_mat = horzcat(data{k,:}); out_filename = strcat(out_basename,num2str(k),'.out'); fid = fopen(out_filename,'w'); col = 1:numel(data_mat) fprintf(fid,'%s\n',data_mat{:,col}); end fclose(fid); end
Comments
Post a Comment