Reading text file data into matrices for selective plotting

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

Reading text file data into matrices for selective plotting

usagi713
I am a beginner to Octave and thus a little unfamiliar with some of the commands; so, I apologize in advance.

I have a .txt file with only numerical data (tab-separated) in four columns. Here are a few lines from the file:
389.28461 500 5.00E-03 1.00E-03
284.69223 500 1.60E-02 1.00E-03
390.87271 50 5.00E-04 1.00E-03
390.89734 5 5.00E-04 1.00E-03
390.89981 0.5 5.00E-04 1.00E-03
390.90009 5.00E-03 5.00E-04 1.00E-03

I want to write a script that will go through the file, read the values into a matrix, and then make 3-D plots for certain constant values in some of the columns. (To better explain that last part, let's say I wanted to keep the third column values constant. So, the first column would be my Z-values, the second column would be the X-values, and the fourth column would be the Y-values for graphs having the same value in the third column. Based on the example lines from the file, the last four lines would be graphed on the same graph, while the first two lines would be graphed on other graphs because they have different values in the third column.)

I am thinking that the first part should be relatively simple. I used the command

load("C:\\Octave\\Test\\data.txt")

which seemed to work, but I don't know where the data is being stored, i.e., what is the name of the matrix in which the data is being stored?

Once I know that, I suppose there is probably some way to write a script that will go through the matrix and only graphing the rows with a certain value in one of the columns.

If you could offer some insight on what I am trying to do, it would be very much appreciated. Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Reading text file data into matrices for selective plotting

Doug Stewart-4


On Wed, Jun 8, 2011 at 1:25 PM, usagi713 <[hidden email]> wrote:
I am a beginner to Octave and thus a little unfamiliar with some of the
commands; so, I apologize in advance.

I have a .txt file with only numerical data (tab-separated) in four columns.
Here are a few lines from the file:
389.28461       500     5.00E-03        1.00E-03
284.69223       500     1.60E-02        1.00E-03
390.87271       50      5.00E-04        1.00E-03
390.89734       5       5.00E-04        1.00E-03
390.89981       0.5     5.00E-04        1.00E-03
390.90009       5.00E-03        5.00E-04        1.00E-03

I want to write a script that will go through the file, read the values into
a matrix, and then make 3-D plots for certain constant values in some of the
columns. (To better explain that last part, let's say I wanted to keep the
third column values constant. So, the first column would be my Z-values, the
second column would be the X-values, and the fourth column would be the
Y-values for graphs having the same value in the third column. Based on the
example lines from the file, the last four lines would be graphed on the
same graph, while the first two lines would be graphed on other graphs
because they have different values in the third column.)

I am thinking that the first part should be relatively simple. I used the
command

load("C:\\Octave\\Test\\data.txt")

which seemed to work, but I don't know where the data is being stored, i.e.,
what is the name of the matrix in which the data is being stored?

Once I know that, I suppose there is probably some way to write a script
that will go through the matrix and only graphing the rows with a certain
value in one of the columns.

If you could offer some insight on what I am trying to do, it would be very
much appreciated. Thank you!

--

The data is stored in data

 a=load("C:\\Octave\\Test\\data.txt"
now it will be stored in   a

If you use the    whos   command you can see all the variables.
Doug

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Reading text file data into matrices for selective plotting

usagi713
Ah, it is there! Thank you so much! You wouldn't happen to have any ideas about how to plot certain values. I thought about doing some sort of combination of a for loop and a while loop but was unsure of the notation.
Reply | Threaded
Open this post in threaded view
|

Re: Reading text file data into matrices for selective plotting

Doug Stewart-4


On Wed, Jun 8, 2011 at 2:02 PM, usagi713 <[hidden email]> wrote:
Ah, it is there! Thank you so much! You wouldn't happen to have any ideas
about how to plot certain values. I thought about doing some sort of
combination of a for loop and a while loop but was unsure of the notation.

--
View this message in context: http://octave.1599824.n4.nabble.com/Reading-text-file-data-into-matrices-for-selective-plotting-tp3583138p3583230.html
Sent from the Octave - General mailing list archive at Nabble.com.

Here are some ideas.  

Note: this is not my area of expertise!!!

a=[389.28461 500 5.00E-03 1.00E-03

284.69223 500 1.60E-02 1.00E-03

390.87271 50 5.00E-04 1.00E-03

390.89734 5 5.00E-04 1.00E-03

390.89981 0.5 5.00E-04 1.00E-03

390.90009 5.00E-03 5.00E-04 1.00E-03

]

b=((a==5.0000e-04))

[m,n,o,p]=find(b)

q=a(m,:,:,:)

r=[q(:,1) q(:,2) q(:,4)] 

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Reading text file data into matrices for selective plotting

usagi713
Thank you very much! I modified what you suggested a bit in the following way:

c=((a(:,3)==5.000e-04))
[d,e,f,g]=find(c)
h=a(d,:,:,:)
x=h(:,2)
y=h(:,4)
z=h(:,1)

This keeps everything constant for values of 5e-04 for the third column, and so the h matrix looks good. When I do plot3(x,y,z), it gives a very odd-looking graph though. Would you say that I choosing the right way to display this, or am I missing something?
Reply | Threaded
Open this post in threaded view
|

Re: Reading text file data into matrices for selective plotting

Doug Stewart-4


On Wed, Jun 8, 2011 at 3:37 PM, usagi713 <[hidden email]> wrote:
Thank you very much! I modified what you suggested a bit in the following
way:

c=((a(:,3)==5.000e-04))
[d,e,f,g]=find(c)
h=a(d,:,:,:)
x=h(:,2)
y=h(:,4)
z=h(:,1)

This keeps everything constant for values of 5e-04 for the third column, and
so the h matrix looks good. When I do plot3(x,y,z), it gives a very
odd-looking graph though. Would you say that I choosing the right way to
display this, or am I missing something?


take a look at surf and meshgrid

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Reading text file data into matrices for selective plotting

usagi713
surf(x,y,z) produces a blank graph and gives the following errors:

error: surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)
error: called from:
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surface.m at line 111, column 9
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surface.m at line 51, column 5
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surf.m at line 47, column 5

meshgrid(x,y,z) produces a large array of values that look like they might have some connection to the original matrix but I am not entirely sure how.
Reply | Threaded
Open this post in threaded view
|

Re: Reading text file data into matrices for selective plotting

Doug Stewart-4


On Wed, Jun 8, 2011 at 3:54 PM, usagi713 <[hidden email]> wrote:
surf(x,y,z) produces a blank graph and gives the following errors:

error: surface: rows (z) must be the same as length (y) and columns (z) must
be the same as length (x)
error: called from:
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surface.m at line
111, column 9
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surface.m at line
51, column 5
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surf.m at line
47, column 5

meshgrid(x,y,z) produces a large array of values that look like they might
have some connection to the original matrix but I am not entirely sure how.

--
use meshgrid to make a new xx and yy
and use the new xx and yy in the surf

see help surf and help meshgrid
 

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Reading text file data into matrices for selective plotting

usagi713
I did the following:

[XX,YY,ZZ]=meshgrid(x,y,z)
surf(XX,YY,ZZ)

The first line worked without errors, but the second line produced quite a few errors:

error: invalid value for array property "xdata"
error: set: expecting argument 2 to be a property name
error: set: expecting argument 4 to be a property name
error: set: expecting argument 6 to be a property name
error: called from:
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surface.m at line 150, column 7
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surface.m at line 51, column 5
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surf.m at line 47, column 5
error: __go_draw_axes__: invalid grid data
error: called from:
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\__go_draw_axes__.m at line 903, column 8
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\__go_draw_figure__.m at line 92, column 3
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\gnuplot_drawnow.m at line 99, column 5
Reply | Threaded
Open this post in threaded view
|

Re: Reading text file data into matrices for selective plotting

Doug Stewart-4


On Wed, Jun 8, 2011 at 5:00 PM, usagi713 <[hidden email]> wrote:
I did the following:

[XX,YY,ZZ]=meshgrid(x,y,z)
surf(XX,YY,ZZ)

The first line worked without errors, but the second line produced quite a
few errors:

error: invalid value for array property "xdata"
error: set: expecting argument 2 to be a property name
error: set: expecting argument 4 to be a property name
error: set: expecting argument 6 to be a property name
error: called from:
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surface.m at line
150, column 7
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surface.m at line
51, column 5
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\surf.m at line
47, column 5
error: __go_draw_axes__: invalid grid data
error: called from:
error:
C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\__go_draw_axes__.m at
line 903, column 8
error:
C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\__go_draw_figure__.m at
line 92, column 3
error: C:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\plot\gnuplot_drawnow.m
at line 99, column 5

--

I think that you have to make a 2 dim array the length and width of your x and y, and put the z values in it.

for your example, I would suggest a 20 by 20 array
z(20,20)=0, will make the empty z array, then you should put your z values into this array at the correct location.
Since your data goes from 500 down to .005 you would have to map this to one axes between 1 and 20
and your other axes is all 1e-3 then you would have to map this to the other axes from 1 to 20

Once you have decided on a mapping from your coordinates to the 1-20 ranges and put your data in the proper places in the z(20,20) array then surf should work.

HTH 
doug


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave