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: Martin Helm
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 00:17:30 +0200

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]