I load 310 txt-files (each of them has 1000 rows and 31 columns) from a directory with the following code:
function create_paramfileclear all, close all% create 310 * 1000 parameter-files
% first step: load all files
pathname = 'C:\Users\Documents\MATLAB\ma\sesxc';files = dir(fullfile(pathname,'*.txt'));for k=1:length(files) param = load(fullfile(pathname, files(k).name),'-ascii'); alb_newsnow=param(:,1); alb_oldsnow=param(:,2); alb_decrease=param(:,3); ... n = length(param); % param has 1000 rows and 31 columns
The load command works fine and all txt-files are listed in the Workspace of the Matlab-Window.
In the next step, (within the function create_paramfile), I try to write alb_newsnow, … to a new structured txt-file. The code therefore is:
my_dir = pwd; cd(my_dir); addpath(genpath(my_dir)); cd([ my_dir '/new_xc']); % delete param.ini files within im my_dir/new_xc
delete('*.ini') % write all files for new parameter
for i=1:n; file_name = ['param' num2str(k(:)) num2str(i(:).') '.ini']; save(file_name); fid = fopen(file_name,'w'); fprintf(fid,'%s\n','#---'); fprintf(fid,'%s\n','#Parameter File for model'); fprintf(fid,'%s\n','#----'); fprintf(fid,'%s\n','#<ALBEDO>'); fprintf(fid,'%s\t','alb_newsnow'); fprintf(fid,'%g\n',alb_newsnow(i,1)); fprintf(fid,'%s\t','alb_oldsnow'); fprintf(fid,'%g\n',alb_oldsnow(i,1)); fprintf(fid,'%s\t','alb_decrease'); fprintf(fid,'%g\n',alb_decrease(i,1));endend
The problem is that only the first of 310 txt-files is processed. That means that I get 1000 files from this file and no output for the second, third, … file. If everything would run correctly, finally, 310000 files would have to be written.
Where could be the problem?
Best Answer