I am now simulating a parabola differential equation using a FDTD-like method. The simulation area is differenced and in order to keep the convergence of simulation, footstep of the mesh is very small so that the matrix scale is very huge, like 2100*100000000. So I cannot directly run simulation in this matrix.
I choose to store only 1 column of data in the program, at the end of the loop each time, I want to write the data to a file, appending the current column to the previous ones. After the simulation is finished, I will import this file into MATLAB and do some plotting like HeatMap.
Here is my sample code:
for n = 1 : z
for m = 2 : (x - 1)
if ((mod(m, 54) < 15) && (mod(m, 54) > 0)) || ((mod(m, 54) < 42) && (mod(m, 54) > 27))
delta_2_E = E(m + 1) - 2 * E(m) + E(m - 1);
E(m) = alpha * delta_2_E + beta(m) * E(m);
end;
end
for m = 1 : x
if (mod(m, 54) == 0) || (mod(m, 54) == 1) || ((mod(m, 54) >= 15) && (mod(m, 54) == 28)) || ((mod(m, 54) >= 42) && (mod(m, 54) <= 53))
E(m) = 0;
end
end
intensity = abs(E);
fidresult = fopen('final_result.txt', 'w');
fprintf(fidresult,' %f\t %f\t %f\n',intensity);
fclose(fidresult);
end
Now here come the questions:
You could write your data into a binary file (ch.mathworks.com/help/matlab/ref/fwrite.html). It is super fast to read (fread
) and quit small data size compared to a txt file.
You could also just use .mat files, which are in hdf5 format (depending on your matlab version). You can create .mat files by just using the save
command