help-octave
[Top][All Lists]
Advanced

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

Re: How to plot two graphs with a textfile with a textdocument with two


From: Markus Bergholz
Subject: Re: How to plot two graphs with a textfile with a textdocument with two x two columns?
Date: Fri, 14 Mar 2014 23:40:41 +0100



On Fri, Mar 14, 2014 at 10:42 PM, Conrad Kopernikus <address@hidden> wrote:
Dear Community,

with some physic experiments with picoscope I get a textfile (.txt) with two
columns. But I have to graphs. My textfile look a littlebit like that:

Channel A
Time     Value
(ms)    (mV)
3       6305
19      6178
34      6081
50      5905
66      5758
81      5641
97      5592
112     5573

Channel B
Time     Value
(ms)    (mV)
3       8864
19      8796
34      8786
50      8786
66      8816
81      8786
97      8786
112     8737

The columns are larger in reality. But how to plot that? I delete the text
and copy the columns for the first graph in a new text-file and the second
in a new text-file. I load both textfiles use the x1=(:,1) and get a plot
like: plot(x1,y1,x2,y2). That works. But is their a faster way to do that?
Can I just use one and same textfile ... but just say to octave it should
make to graphs instead of connecting them?



octave:1> f=fopen('conrad.txt' )
f =                    3
octave:2> raw=fread (f, "char=>char").'
raw = Channel A
Time     Value
(ms)    (mV)
3       6305
19      6178
34      6081
50      5905
66      5758
81      5641
97      5592
112     5573

Channel B
Time     Value
(ms)    (mV)
3       8864
19      8796
34      8786
50      8786
66      8816
81      8786
97      8786
112     8737

octave:3> rawvalues=regexp(raw,"[0-9]+",'match')
rawvalues = 
{
  [1,1] = 3
  [1,2] = 6305
  [1,3] = 19
  [1,4] = 6178
  [1,5] = 34
  [1,6] = 6081
  [1,7] = 50
  [1,8] = 5905
  [1,9] = 66
  [1,10] = 5758
  [1,11] = 81
  [1,12] = 5641
  [1,13] = 97
  [1,14] = 5592
  [1,15] = 112
  [1,16] = 5573
  [1,17] = 3
  [1,18] = 8864
  [1,19] = 19
  [1,20] = 8796
  [1,21] = 34
  [1,22] = 8786
  [1,23] = 50
  [1,24] = 8786
  [1,25] = 66
  [1,26] = 8816
  [1,27] = 81
  [1,28] = 8786
  [1,29] = 97
  [1,30] = 8786
  [1,31] = 112
  [1,32] = 8737
}
octave:4> cellvalue=cellfun (@str2double, rawvalues, 'UniformOutput', false)
cellvalue = 
{
  [1,1] =                    3
  [1,2] =                 6305
  [1,3] =                   19
  [1,4] =                 6178
  [1,5] =                   34
  [1,6] =                 6081
  [1,7] =                   50
  [1,8] =                 5905
  [1,9] =                   66
  [1,10] =                 5758
  [1,11] =                   81
  [1,12] =                 5641
  [1,13] =                   97
  [1,14] =                 5592
  [1,15] =                  112
  [1,16] =                 5573
  [1,17] =                    3
  [1,18] =                 8864
  [1,19] =                   19
  [1,20] =                 8796
  [1,21] =                   34
  [1,22] =                 8786
  [1,23] =                   50
  [1,24] =                 8786
  [1,25] =                   66
  [1,26] =                 8816
  [1,27] =                   81
  [1,28] =                 8786
  [1,29] =                   97
  [1,30] =                 8786
  [1,31] =                  112
  [1,32] =                 8737
}
octave:5> matvalue=cell2mat (cellvalue )
matvalue =

 Columns 1 through 23:

                     3                  6305                    19                  6178                    34                  6081                    50                  5905                    66                  5758                    81                  5641                    97                  5592                   112                  5573                     3                  8864                    19                  8796                    34                  8786                    50

 Columns 24 through 32:

                  8786                    66                  8816                    81                  8786                    97                  8786                   112                  8737

octave:6> 




don't know, it's completly unsorted. maybe iterative is more easy and more slow

e.g. conrad.m

fid=fopen('conrad.txt');
row=1;
while 1
      raw = fgetl(fid);
      if ~ischar(raw)
          break %end of file, break!
      end

      data="">
      if numel(data)~=0
          m(row,1:2)=str2double(data);
          row++;
     end
end
fclose(fid) 

octave:1> conrad
ans =                    0
octave:2> m
m =

                     3                  6305
                    19                  6178
                    34                  6081
                    50                  5905
                    66                  5758
                    81                  5641
                    97                  5592
                   112                  5573
                     3                  8864
                    19                  8796
                    34                  8786
                    50                  8786
                    66                  8816
                    81                  8786
                    97                  8786
                   112                  8737


Take care, this will fail/don't work correctly if there is a decimalpoint value....


reply via email to

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