From: Ryan on
I have a code written that combines data from text files into a single text document. The code is as follows:
fid=fopen('datafile.txt','w+');
files = dir('*af1*');

for i=1:length(files)
eval(['load ' files(i).name ' -ascii'])
A(i,1)=textread(files(i).name, '%f');
fprintf(fid,'%s\t %-f\r\n ',files(i).name,A(i));
end

fclose(fid);

This gets all of the filenames printed with the value from their file printed one tab space away from them. Is there a way to get the filenames to be printed to the left column, and the values into a separate column (so that they are all aligned)?

Right now A is a 21x1 double. Since the filenames are strings, I cannot just use the cat function to combine them into one matrix. Maybe there is a similar function to cat that i can use?
From: Jan Simon on
Dear Ryan,

> fid=fopen('datafile.txt','w+');
> files = dir('*af1*');
> for i=1:length(files)
> eval(['load ' files(i).name ' -ascii'])
> A(i,1)=textread(files(i).name, '%f');
> fprintf(fid,'%s\t %-f\r\n ',files(i).name,A(i));
> end
> fclose(fid);

EVAL is not needed. Just write:
load(files(i).name, '-ascii');

> This gets all of the filenames printed with the value from their file printed one tab space away from them. Is there a way to get the filenames to be printed to the left column, and the values into a separate column (so that they are all aligned)?

I'm not sure, what a "column" is. Perhaps you want to specify the width of the output:
fprintf(fid,'%-20s\t %-f\r\n ',files(i).name,A(i));

> Right now A is a 21x1 double. Since the filenames are strings, I cannot just use the cat function to combine them into one matrix. Maybe there is a similar function to cat that i can use?

You can use SPRINTF to convert the elements of A to a string. But this depends on the output you prefer.

Good luck, Jan