### Tags: becomes, dear, file, following, integer, integrating, keeping, matlab, matrix, output, pde, problemi, programming, record, save, solution, whenever

# save matrix on output file

On Programmer » Matlab

2,304 words with 0 Comments; publish: Wed, 07 May 2008 14:40:00 GMT; (200109.38, « »)

Dear All,

I have the following problem:

I am integrating a PDE and I am keeping record of my solution, say v(N), whe

never t becomes integer (N is the number of spatial grid points).

The result of this is a matrix, say plotdata(i,N), whose rows are the variou

s vectors v(N) recorded at increasing values of the counter i (which runs on

time).

Now, if I keep plotdata(i,:) in memory and I just use the command 'save' at

the end of the loop, what happens is that if N is large enough I exceed the

memory limit.

In any case, even if I do not go beyond the memory limit, it produces a dram

atic increase of running time of the code.

I have tried to use 'append' in order to save

plotdata(i,:) at any time the counter 'i' is updated and the clear plotdata

from memory, but the result of this is that plotdata(i+1,:) is going to be w

ritten over plotdata(i,N) and so the only array plotdata(i+1,:) remains writ

ten in the output file.

I know that I need to use fopen, fwrite, fclose but I am becoming crazy with

the various formats and precision...

Could you be so kind to help me to write these few lines of my code?

At the beginning of my code I have set 'format long'.

The result I would like to obtain is an output .mat file where the whole mat

rix plotdata(i,:) is written together with the other quantities I need to sa

ve in the .mat file.

If it can be helpful, here it is the part of the code with the loop:

for i=1:nplots

for n=1:plotgap

nonlin = v.^3;

nonlin(1,1)=0;

nonlin(N,1)=0;

v = T1\(T2*v - nonlin*dt);

udat = [udat; v(round(3*N/4))];

vdat = [vdat; v(round(N/2))];

wdat = [wdat; v(round(N/4))];

xdat = [xdat; norm(v,2)];

t=t+dt

end

plotdata(i+1,:)=v';

%save ('/home/amsta/fsarnari/hopf/B.mat', 'plotdata(i+1,:)') -append

%save ('B.mat', '-append', 'plotdata')

%save ('B.mat', 'plotdata')

%clear plotdata

tdata=[tdata; t];

[r_bc_r,r_bc_l]=check_BC(beta, gamma, L, P, v, N);

R_bc_r(i+1,:)=r_bc_r;

R_bc_l(i+1,:)=r_bc_l;

end

Thanks very much to whom will help me on this.

Francesco

*http://matlab.questionfor.info/q_matlab_53129.html*

All Comments

Leave a comment...

- 0 Comments