MATLAB: Save a data as mat file

.mat file

Hi
%

%
for i=113:113
data=[];
fileID = fopen(['Printout_' num2str(i) '.txt']);
block = textscan(fileID, '%s','Delimiter','\n');
data=[data; block];
fclose(fileID);
compact_data=vertcat(data{:});
compact_data(1:29:end)=[];
compact_data(1:28:end)=[];
result_file=fopen(['result_probe_' num2str(i) '.txt'],'w');
fprintf(result_file,'%s\r\n',compact_data{1:1:end});
clear all
end
thank you for the fast response. but how could i do it as whe the loop is going from 113 to 200. it means somthing like this:
maymatlabefile113.mat
maymatlabefile114.mat
maymatlabefile115.mat
maymatlabefile116.mat … . . .maymatlabefile200.mat

Best Answer

I would recommend putting everything in a cell array, that you can then save.
all_data = cell(10,1);
for ii = 1:10
all_data(i) = {your_data};
end
save your_file.mat your_data;
Having all those files can lead to problems. However, here is a solution
nameStr = 'your_file';
for ii = 1:10
tempStr = [your_file num2str(ii) '.mat'];
save(tempStr ,'your_data');
end