Load different files then converting them into .txt files

Hey everyone,
%%To load data from the (.mat) files and then convert them to (.txt) files
a=['20MIN_SCHJ300639_220208.mat' '20MIN_SEMS170640_040608.mat' '20MIN_SIMG200162_060208.mat'];
for i=1:3
fid = fopen('Data%i.txt', 'w');
load('a(i)');
fprintf (fid, '%.9f \r\n', data_block1);
fclose(fid);
end
I'm having an error in load('a(i)')!! How can I make it work?

 Accepted Answer

Make a a cell array of strings:
a={'20MIN_SCHJ300639_220208.mat' '20MIN_SEMS170640_040608.mat' '20MIN_SIMG200162_060208.mat'};
for i=1:3
fid = fopen('Data%i.txt', 'w');
load( a{i} );
fprintf (fid, '%.9f \r\n', data_block1);
fclose(fid);
end

7 Comments

OK the error is gone but it only loaded and converted data from one file only!! I want to convert each .mat file into a separate .txt file.
fid = fopen('Data%i.txt', 'w'); % i here is for the looping and I guess it is not working
fopen( sprintf('Data%d.txt',i), 'w');
no ???
After running the program for 70 files:
for i=1:70
fid = fopen( sprintf('Data%d.txt',i), 'w');
load(a{i});
fprintf (fid, '%.9f \r\n', data_block1);
fclose(fid);
end
I noticed that when I write whos I get data_block1, data_block2 and data_block3,, however when i load each file alone -I chose random files for testing- I only get data_block1!! Do you know why is this happening!!
What happens if you only load two files? (do you get data_block1 and data_block2 then?)
I loaded each one of the files separately to find the error!! So, I found 3 files out of the 70 that contain 3 data blocks. I removed them from the cell array and loaded them by themselves. I also found another error in the way I wrote my cell array, I fixed it and finally it worked properly!!

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!