eliminte "ans" and print file as is on the screen

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

eliminte "ans" and print file as is on the screen

eugenia
Hi!
since a few days I am trying to plot something. I think I found a way but I
need to print a file with the same format I see on the screen but I need to
eliminate "ans".
I have a variable CHIS1.
>> disp(CHIS1(1,:,:))
ans(:,:,1) =

   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04  
3.5576e-04

ans(:,:,2) =

   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04  
4.0325e-04

ans(:,:,3) =

3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04   0.0000e+00
.
..

An I want to print this in a file (without "ans")  with this format:

   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04  
3.5576e-04
   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04  
4.0325e-04
  3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04  
0.0000e+00
.
.


I tried to apply many instructions on the web but they didn't work... Can
somebody help me?

Regards,
Marie Eugenia



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

Carlo de Falco-2


> On 10 Jan 2019, at 12:05, eugenia <[hidden email]> wrote:
>
> Hi!
> since a few days I am trying to plot something. I think I found a way but I
> need to print a file with the same format I see on the screen but I need to
> eliminate "ans".
> I have a variable CHIS1.
>>> disp(CHIS1(1,:,:))
> ans(:,:,1) =
>
>   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04  
> 3.5576e-04
>
> ans(:,:,2) =
>
>   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04  
> 4.0325e-04
>
> ans(:,:,3) =
>
> 3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04   0.0000e+00
> .
> ..
>
> An I want to print this in a file (without "ans")  with this format:
>
>   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04  
> 3.5576e-04
>   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04  
> 4.0325e-04
>  3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04  
> 0.0000e+00
> .
> .
>
>
> I tried to apply many instructions on the web but they didn't work... Can
> somebody help me?
>
> Regards,
> Marie Eugenia

try

  disp (squeeze (CHIS1(1,:,:)))

to show the data on screen and

  A = squeeze (CHIS1(1,:,:));
  save -ascii my_file.txt A

to save it to file,
c.






Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

eugenia
In reply to this post by eugenia
I tried with this:
file_id=fopen("soloamp.txt","w")
file_id =  35
fdisp("soloamp.txt",CHIS1(1,:,:))
fclose(file_id)
ans = 0

but the content of the file is:
ans(:,:,1) =

   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04  
3.5576e-04

ans(:,:,2) =

   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04  
4.0325e-04

ans(:,:,3) =

   3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04  
0.0000e+00
....





--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

eugenia
In reply to this post by Carlo de Falco-2
Thank you Carlo,
but it does not do what I want.
If I follow your instructions I get a file which is a mess and that is what
I am trying to avoid.
Because....
.>> disp (squeeze (CHIS1(1,:,:)))
 Columns 1 through 12:

   0.0003321   0.0007816   0.0003918   0.0004652   0.0003442   0.0003655  
0.0010181   0.0003418   0.0005266   0.0003403   0.0002409   0.0006707
   0.0003614   0.0006442   0.0002523   0.0004484   0.0003358   0.0003855  
0.0010470   0.0002202   0.0005846   0.0003947   0.0002115   0.0004387
   0.0003440   0.0006848   0.0004559   0.0004898   0.0003919   0.0003622  
0.0010785   0.0003304   0.0006562   0.0003842   0.0002543   0.0006066
   0.0003228   0.0005500   0.0003998   0.0004115   0.0004300   0.0003189  
0.0007936   0.0002989   0.0005549   0.0003759   0.0003225   0.0005277
   0.0003049   0.0004839   0.0003898   0.0004277   0.0003398   0.0003462  
0.0007191   0.0003381   0.0004393   0.0003045   0.0001453   0.0004469
   0.0003558   0.0004032   0.0000000   0.0004472   0.0004155   0.0003189  
0.0005290   0.0000000   0.0005020   0.0003365   0.0001966   0.0000000

 Columns 13 through 24:

   0.0011299   0.0006522   0.0004936   0.0004170   0.0003052   0.0001684  
0.0005087   0.0002559   0.0002373   0.0006324   0.0012633   0.0004249
   0.0011320   0.0006401   0.0003937   0.0003409   0.0001955   0.0001868  
0.0004594   0.0002414   0.0002106   0.0007266   0.0012741   0.0003471
   0.0010680   0.0006666   0.0003674   0.0005126   0.0002986   0.0002784  
0.0005556   0.0002681   0.0002380   0.0006209   0.0012610   0.0003332
   0.0009086   0.0006051   0.0003454   0.0004252   0.0002606   0.0002425  
0.0004255   0.0002846   0.0002549   0.0005994   0.0010634   0.0003459
   0.0007782   0.0005833   0.0003624   0.0004182   0.0002846   0.0002242  
0.0004564   0.0001651   0.0002005   0.0006111   0.0010626   0.0004016
   0.0005422   0.0004830   0.0002224   0.0000000   0.0000000   0.0000000  
0.0004698   0.0001917   0.0001979   0.0007246   0.0008007   0.0004367

 Columns 25 through 36:

the saved file is full of numbers without any format.  

Regards



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

Doug Stewart-4
In reply to this post by eugenia


On Thu, Jan 10, 2019 at 6:06 AM eugenia <[hidden email]> wrote:
Hi!
since a few days I am trying to plot something. I think I found a way but I
need to print a file with the same format I see on the screen but I need to
eliminate "ans".
I have a variable CHIS1.
>> disp(CHIS1(1,:,:))
ans(:,:,1) =

   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04 
3.5576e-04

ans(:,:,2) =

   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04 
4.0325e-04

ans(:,:,3) =

3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04   0.0000e+00
.
..

An I want to print this in a file (without "ans")  with this format:

   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04 
3.5576e-04
   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04 
4.0325e-04
  3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04 
0.0000e+00
.
.


I tried to apply many instructions on the web but they didn't work... Can
somebody help me?

Regards,
Marie Eugenia




here is one way:

clear
a=rand(2,3,6);
for k=1:6
q(:,k)=a(1,:,k);
endfor
display(q)

what the trick here is---  to make it into a 2d array first then display it.
I hope this helps.
Doug
 
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html




--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

Doug Stewart-4


On Thu, Jan 10, 2019 at 6:36 AM Doug Stewart <[hidden email]> wrote:


On Thu, Jan 10, 2019 at 6:06 AM eugenia <[hidden email]> wrote:
Hi!
since a few days I am trying to plot something. I think I found a way but I
need to print a file with the same format I see on the screen but I need to
eliminate "ans".
I have a variable CHIS1.
>> disp(CHIS1(1,:,:))
ans(:,:,1) =

   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04 
3.5576e-04

ans(:,:,2) =

   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04 
4.0325e-04

ans(:,:,3) =

3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04   0.0000e+00
.
..

An I want to print this in a file (without "ans")  with this format:

   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04 
3.5576e-04
   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04 
4.0325e-04
  3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04 
0.0000e+00
.
.


I tried to apply many instructions on the web but they didn't work... Can
somebody help me?

Regards,
Marie Eugenia




here is one way:

clear
a=rand(2,3,6);
for k=1:6
q(:,k)=a(1,:,k);
endfor
display(q)

what the trick here is---  to make it into a 2d array first then display it.
I hope this helps.
Doug
 
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html





try this
clear
a=rand(2,3,6);
for k=1:6
q(:,k)=a(1,:,k);
endfor
display(q)
save out.dta -ascii q
 

--
DASCertificate for 206392



--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

Doug Stewart-4


On Thu, Jan 10, 2019 at 6:43 AM Doug Stewart <[hidden email]> wrote:


On Thu, Jan 10, 2019 at 6:36 AM Doug Stewart <[hidden email]> wrote:


On Thu, Jan 10, 2019 at 6:06 AM eugenia <[hidden email]> wrote:
Hi!
since a few days I am trying to plot something. I think I found a way but I
need to print a file with the same format I see on the screen but I need to
eliminate "ans".
I have a variable CHIS1.
>> disp(CHIS1(1,:,:))
ans(:,:,1) =

   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04 
3.5576e-04

ans(:,:,2) =

   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04 
4.0325e-04

ans(:,:,3) =

3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04   0.0000e+00
.
..

An I want to print this in a file (without "ans")  with this format:

   3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04 
3.5576e-04
   7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04 
4.0325e-04
  3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04 
0.0000e+00
.
.


I tried to apply many instructions on the web but they didn't work... Can
somebody help me?

Regards,
Marie Eugenia




here is one way:

clear
a=rand(2,3,6);
for k=1:6
q(:,k)=a(1,:,k);
endfor
display(q)

what the trick here is---  to make it into a 2d array first then display it.
I hope this helps.
Doug
 
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html





try this
clear
a=rand(2,3,6);
for k=1:6
q(:,k)=a(1,:,k);
endfor
display(q)
save out.dta -ascii q
 

--
DASCertificate for 206392



--
DASCertificate for 206392

or this:

clear
a=rand(2,3,6);
q=squeeze(a(1,:,:));
display(q)
save out.dta -ascii q

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

marco atzeri-2
In reply to this post by eugenia
Am 1/10/2019 um 3:05 AM schrieb eugenia:

> Hi!
> since a few days I am trying to plot something. I think I found a way but I
> need to print a file with the same format I see on the screen but I need to
> eliminate "ans".
> I have a variable CHIS1.
>>> disp(CHIS1(1,:,:))
> ans(:,:,1) =
>
>     3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04
> 3.5576e-04
>
> ans(:,:,2) =
>
>     7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04
> 4.0325e-04
>
> ans(:,:,3) =
>
> 3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04   0.0000e+00
> .
> ..
>
> An I want to print this in a file (without "ans")  with this format:
>
>     3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04
> 3.5576e-04
>     7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04
> 4.0325e-04
>    3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04
> 0.0000e+00

>
> I tried to apply many instructions on the web but they didn't work... Can
> somebody help me?
>
> Regards,
> Marie Eugenia

Hi Marie Eugenia,

look at reshape on
https://octave.org/doc/interpreter/Rearranging-Matrices.html#Rearranging-Matrices

as it seems you want to convert from a 3 indices matrix
to a 2 indices matrix , or a portion of it

a=rand(2,3,4)
a =

ans(:,:,1) =

    0.359352   0.036676   0.803829
    0.552612   0.733710   0.406368

ans(:,:,2) =

    0.82129   0.80905   0.81632
    0.55000   0.18838   0.96678

ans(:,:,3) =

    0.77684   0.39601   0.54564
    0.29402   0.12709   0.55232

ans(:,:,4) =

    0.477781   0.044654   0.720754
    0.562815   0.571051   0.174492

octave:33> b=reshape(a,2,3*4)
b =

  Columns 1 through 7:

    0.359352   0.036676   0.803829   0.821287   0.809049   0.816319
0.776840
    0.552612   0.733710   0.406368   0.549999   0.188378   0.966778
0.294024

  Columns 8 through 12:

    0.396012   0.545636   0.477781   0.044654   0.720754
    0.127094   0.552318   0.562815   0.571051   0.174492

octave:34> size(b)
ans =

     2   12

octave:35> b=reshape(a(1,:,:),3,4)
b =

    0.359352   0.821287   0.776840   0.477781
    0.036676   0.809049   0.396012   0.044654
    0.803829   0.816319   0.545636   0.720754

octave:36> size(b)
ans =

    3   4









---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus



Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

eugenia
In reply to this post by Doug Stewart-4
Thanks to both, but it is not worknig with my variable. Your examples work
really fine.

I need to print exactly what I see on the screen. I could do if my variable
is CHIS (1,1,:). In this case is something like this:
3.32078635e-04
 7.81565381e-04
 3.91836162e-04
 ..

But I need to vary the second index which indicates 6 different channels.
So, the output must be:
3.3208e-04   3.6136e-04   3.4397e-04   3.2282e-04   3.0488e-04  3.5576e-04
7.8157e-04   6.4418e-04   6.8477e-04   5.5001e-04   4.8390e-04  4.0325e-04
3.9184e-04   2.5231e-04   4.5585e-04   3.9979e-04   3.8978e-04 0.0000e+00

... at least with your indications I could write 6 different files and then,
maybe with AWK, I can put them all together. But then... I should do the
same for the first index, so with CHIS1(2,:,:)...

Regards
Maria Eugenia



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

mmuetzel
Is this what you want to do?
CHIS = rand(2,6,3)/1e3;
fid = fopen ('CHIS1.txt', 'w');
fprintf (fid, '%.4e %.4e %.4e %.4e %.4e %.4e\n', squeeze (CHIS(1,:,:)));
fclose (fid);

Markus



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: eliminte "ans" and print file as is on the screen

eugenia
In reply to this post by eugenia
Thanks for the ideas because I found the way,
I used:
a=squeeze(CHIS1(1,:,:))

and then transpose a
b=a'

So...
b =

   0.0003321   0.0003614   0.0003440   0.0003228   0.0003049   0.0003558
   0.0007816   0.0006442   0.0006848   0.0005500   0.0004839   0.0004032
   0.0003918   0.0002523   0.0004559   0.0003998   0.0003898   0.0000000
   0.0004652   0.0004484   0.0004898   0.0004115   0.0004277   0.0004472
   0.0003442   0.0003358   0.0003919   0.0004300   0.0003398   0.0004155
   0.0003655   0.0003855   0.0003622   0.0003189   0.0003462   0.0003189
   0.0010181   0.0010470   0.0010785   0.0007936   0.0007191   0.0005290


This is what i was looking for.
Thanks!

Maria Eugenia



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html