help-octave
[Top][All Lists]
Advanced

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

Re: Fw: how loading a data file with complex number from a\ .dat\ file t


From: Tina Shord
Subject: Re: Fw: how loading a data file with complex number from a\ .dat\ file to a matrix in octave
Date: Tue, 18 Oct 2011 04:18:51 -0700 (PDT)

Dear Mr Helm,

I don't how to appreciate your help. your advice was very helpful. I have done what you said
 an wrote the commands you said in terminal and the result was exactly what you said.
but if it is possible I would like to ask another question. in the past I created a /.m/ file
(a simple .m file which work for me for real number and don't work for complex number which is written
 at the end of the text) and it was collected all my real data. I really like to know can i create a /.m/ file here
 and work with it. because the way u introduce to me put all data in terminal and
 I don't know how to collect them and put them in a single matrix. 

my m file:

[fid,msg] = fopen ("~/Desktop/trans.dat","r");
[val,count] = fscanf (fid," transmitted field:, %f,  %f",Inf);
fclose (fid);

ncolmn=2;
num=length(val)/ncolmn;
trans=zeros(num,1);
time=zeros(num,1);

for m=1:num
   
    time(m)=val(ncolmn*m-1);
    trans(m)=val(ncolmn*m);
    
end

hold on
plot(time,trans,'r--o');


From: Martin Helm <address@hidden>
To: Tina Shord <address@hidden>
Cc: "address@hidden" <address@hidden>
Sent: Tuesday, October 18, 2011 1:47 AM
Subject: Re: Fw: how loading a data file with complex number from a\ .dat\ file to a matrix in octave

Am Montag, den 17.10.2011, 14:07 -0700 schrieb Tina Shord:
>
>
>
> Dear octave users,
>
>
> I am a beginner in octave software. for doing my projects I needed to
> load data from a \ .dat\ file by octave.
> when my \ .dat\ file was like this:
>
> transmitted field:,    0.0,          0.0
> transmitted field:,    0.025,    2.499
> transmitted field:,    0.050,    8.744
> transmitted field:,    0.075,    0.001
> .
> .
> .
>
> I used the following command to load this two column number and
> collect them in a matrix:
>
>
> fid = fopen (transmited_data_file, 'r'); ‍
> [val, count] = fscanf (fid, ' transmited field:, %f , %f', Inf);
> fclose(fid);
>     
>
> but now my \.dat\ file consist complex number like this:
>
> transmitted field:,    0.0,          0.0
> transmitted field:,    0.025,
> 2.49980469004312e-4-3.12491862042745e-6i
> transmitted field:,    0.050,
> 8.74462952547355e-4-2.96808679768089e-5i
> transmitted field:,    0.075,
> 0.00159104818877218-9.17427368087194e-5i
> transmitted field:,    0.1,
> 0.00216403420364298-1.87084801577104e-4i
> transmitted field:,    0.125,
> 0.00255133003954042-3.06091873691879e-4i
> transmitted field:,    0.15,
> 0.00288402756349901-4.4210946665116e-4i
> transmitted field:,    0.175,
> 0.00331455558925927-5.96758485768472e-4i
> .
> .
> and above command can not load complex numbers.I really don't know
> what command I should use
> to load these complex number.
> It would be a great hand if you help me and I will be great full.
>
> regards,
> tina,
> address@hidden
>
Did you try the dlmread command, it reads your data just fine with a
single line of code:

transmited_data_file = 'test.dat'
val = dlmread (transmited_data_file, ",", 0, 1);

Here is what it results in

octave:1> format free
octave:2> transmited_data_file = 'test.dat';
octave:3> val = dlmread (transmited_data_file, ",", 0, 1)
val =

(0,0) (0,0)
(0.025,0) (0.00024998,-3.12492e-06)
(0.05,0) (0.000874463,-2.96809e-05)
(0.075,0) (0.00159105,-9.17427e-05)
(0.1,0) (0.00216403,-0.000187085)
(0.125,0) (0.00255133,-0.000306092)
(0.15,0) (0.00288403,-0.000442109)
(0.175,0) (0.00331456,-0.000596758)





reply via email to

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