how to modify the saved variable in mat file by adding extra columns without overwriting on the previously saved columns
1 view (last 30 days)
Show older comments
I want to modify mat file created without overwriting the previously saved columns. I want to create an array of 12 columns and each column is corresponding to one file. I want to save the data to the mat file after reading 3 consecutive files, then clear the array (rho) to save memory usage on the computer.
I have written the following lines but the finally saved mat file only contains the last 4 files as it overwrites the saved data on the mat file instead of adding extra columns.
is there any method to modify the code to avoid overwriting old saved data on the mat file?
clc
clear
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t_inital=0.484913828;
t_final=0.656613828;
delta_t=5e-5;
klimit=(t_final-t_inital)/delta_t;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%read rho%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t=t_inital;
m = matfile('rho.mat', 'Writable', true);
for k=2:12
tic
t=t+delta_t;
if k==2
file1=readlines('F:\porous rectangular surface\surface\0.484913828\sampledSurface_sampledSurfaceDict\scalarField\rho');% read ASCII file
rho1=str2double(file1(4:end-2));
%rho=rho1;
elseif k==4||k==7||k==10
save('rho.mat','rho');
clear rho;
file1=readlines(['F:\porous rectangular surface\surface\',sprintf('%.9f',t),'\sampledSurface_sampledSurfaceDict\scalarField\rho']);% read ASCII file
rho1=str2double(file1(4:end-2));
else
rho1=rho;
end
file2=readlines(['F:\porous rectangular surface\surface\',sprintf('%.9f',t),'\sampledSurface_sampledSurfaceDict\scalarField\rho']);% read ASCII file
i=k
rho=[rho1,str2double(file2(4:end-2))];
if mod(k,3) == 0
fprintf('file read %d...\n',k);
tt=toc/60
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT-Files 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!