Quantcast

Question on printing ..

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question on printing ..

dieter.jurzitza@t-online.de
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


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question on printing ..

dieter.jurzitza@t-online.de
Dear listmembers,
sorry for the noise - after one day of fiddling (grrrrrr :-) ) my son helped
me out - just give the entire array as parameter and things work like a charm
- and I nearly broke my head how to make this the complicated way ...
Thank you for looking into this,
regards






Dieter Jurzitza

Am Freitag, 5. Mai 2017, 19:56:39 schrieb Dr.-Ing. Dieter Jurzitza:

> 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
**********************

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


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Loading...