help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question on printing ..


From: Dr.-Ing. Dieter Jurzitza
Subject: Question on printing ..
Date: Fri, 05 May 2017 19:56:39 +0200
User-agent: KMail/4.14.10 (Linux/4.1.39-53.4-default; KDE/4.14.18; x86_64; ; )

Dear listmembers,
say you have a function called f having two variables as parameters:

function f(xarray,yarray)
        outfile=fopen("test.dat", "w");
        fprintf(outfile, "%12.8f %12.8f\n", [xarray; yarray[1:]);
        fclose (outfile)
endfunction

assuming xarray being an array of type 1:1000 and yarray being an array of 
type 1:1000 this would write the contents of both arrays into the file 
"test.dat".

So far so good. Now, consider the following situation: you want to write as 
many columns consecutively into the output file as there are in yarray.

For the format string ( "%12.8f %12.8f ....")this is straightforward:

function f(xarray,yarray)
        outfile=fopen("test.dat", "w");
        formatstring="%12.8f";
        fprintf(outfile, [repmat(formatstring,[1 (size(yarray)(1)+1)],"\n"), 
[xarray; yarray(1:); yarray(2:); .... yarray((size(yarray)(1)):)]);
        fclose (outfile)
endfunction

however, how can I do something similar for the variables residing right of 
the formatstring (xarray / yarray)? I have been trying

params="[xarray"
for i=1:size(yarray)(1)
   params=sprintf("%s; yarray(%d:)", params i);
endfor
params=sprintf("%s]",params);

looking at "params" this results in
[xarray; yarray(1:); yarray(2:); ... yarray((size(yarray)(1)):)]
and consequently what I'd like to see on the right side.

But when I write
        fprintf(outfile, [repmat(formatstring,[1 (size(yarray)
(1)+1)],"\n"),params);

after that this doesn't work at all and writes nonsense into "outfile". At the 
end of the day I would like to write as many colums into "outfile" as there 
are - without knowing in advance how many ones this could be.

Any idea how to realize this (if possible at all)?

Thank you very much,
regards




Dieter Jurzitza

-- 
-----------------------------------------------------------
Dr.-Ing. Dieter Jurzitza                    76131 Karlsruhe




reply via email to

[Prev in Thread] Current Thread [Next in Thread]