clear;clc;

cd /home/subhadip/Tumor_Network/Data/analysis/990_regions

%specify the bedpostx directories
chk=dir('*connections_990'); 

for l=17%length(chk)
    

outputdir=strcat('/home/subhadip/Tumor_Network/Data/analysis/990_regions/',chk(l).name );
newoutputdir=strcat('/home/subhadip/Tumor_Network/Data/analysis/990_regions/',chk(l).name );
% [status currdir] = system([' cd ' outputdir ])

% files=dir(outputdir , '/matrix')

for m=1:990
    
chknew=num2str(m,'%03d');
    
filename=strcat(outputdir,'/matrix_region_', chknew , '_to_all_targets.txt')

ch1=num2str(m,'%03d');

newfilename=strcat('region_', ch1 ,'_connections.txt');
newfilepath=strcat(newoutputdir , '/' , newfilename);

M=load(filename);
fid=fopen(newfilepath , 'w');
fprintf(fid,[repmat('%g ',1,size(M,2)),'\n'], M);
fclose(fid); 
size(M)
end

end

