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?

 Akzeptierte Antwort

per isakson
per isakson am 13 Jul. 2012
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 Kommentare

Yasmin Tamimi
Yasmin Tamimi am 13 Jul. 2012
Bearbeitet: Yasmin Tamimi am 13 Jul. 2012
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
F.
F. am 13 Jul. 2012
Bearbeitet: F. am 13 Jul. 2012
fopen( sprintf('Data%d.txt',i), 'w');
no ???
Thankx a lot
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!!
Ryan
Ryan am 13 Jul. 2012
What happens if you only load two files? (do you get data_block1 and data_block2 then?)
Yasmin Tamimi
Yasmin Tamimi am 14 Jul. 2012
Bearbeitet: Yasmin Tamimi am 14 Jul. 2012
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!!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by