From: Mahmood N. <nt_...@ya...> - 2013-09-03 16:34:40
|
Hi, I have a data file which looks like this 100 10 M 150 20 M 30 40 H 50 90 M I want to plot the second column on the rows which has 'M' in their third column (10, 20, 90). Is it possible to directly tell "plot" command to do such thing or not? Otherwise I have to preprocess the file which some languages and then feed it to gnuplot. Regards, Mahmood |
From: BBands <bb...@gm...> - 2013-09-03 16:41:36
|
The ternary operator is what you want. Here is a nice little write up: http://gnuplot-surprising.blogspot.com/2011/09/manipulate-data-using-ternary-operator.html John On Tue, Sep 3, 2013 at 9:34 AM, Mahmood Naderan <nt_...@ya...> wrote: > Hi, > I have a data file which looks like this > > 100 10 M > 150 20 M > 30 40 H > 50 90 M > > I want to plot the second column on the rows which has 'M' in their third column (10, 20, 90). Is it possible to directly tell "plot" command to do such thing or not? Otherwise I have to preprocess the file which some languages and then feed it to gnuplot. |
From: Mahmood N. <nt_...@ya...> - 2013-09-03 16:49:41
|
Thanks for the quick reply. I understood it but I receive error. Again here is the data file 100 10 M 150 20 M 30 40 H 50 90 M So I ran plot "data.txt" u 1:($3=='M':$2:1/0) So I expect that it compares the third column to 'M' and on a match return the second column. Isn't that? Now I receive None-numeric string found where a numeric expression was expected. Regards, Mahmood ________________________________ From: BBands <bb...@gm...> To: Mahmood Naderan <nt_...@ya...>; gnuplot <gnu...@li...> Sent: Tuesday, September 3, 2013 9:11 PM Subject: Re: [Gnuplot-info] ploting if a special character exist in the line The ternary operator is what you want. Here is a nice little write up: http://gnuplot-surprising.blogspot.com/2011/09/manipulate-data-using-ternary-operator.html John On Tue, Sep 3, 2013 at 9:34 AM, Mahmood Naderan <nt_...@ya...> wrote: > Hi, > I have a data file which looks like this > > 100 10 M > 150 20 M > 30 40 H > 50 90 M > > I want to plot the second column on the rows which has 'M' in their third column (10, 20, 90). Is it possible to directly tell "plot" command to do such thing or not? Otherwise I have to preprocess the file which some languages and then feed it to gnuplot. |
From: Leo B. <l_b...@us...> - 2013-09-03 17:35:45
|
>From mailnull Tue Sep 3 16:50:17 2013 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of lists.sourceforge.net designates 172.29.29.180 as permitted sender) client-ip=172.29.29.180; envelope-from=gnu...@li...; helo=lists.sourceforge.net; Date: Tue, 3 Sep 2013 09:49:33 -0700 From: Mahmood Naderan <nt_...@ya...> Reply-To: Mahmood Naderan <nt_...@ya...> Content-Type: text/plain; charset="iso-8859-1" Thanks for the quick reply. I understood it but I receive error. Again here is the data file 100 10 M 150 20 M 30 40 H 50 90 M So I ran plot "data.txt" u 1:($3=='M':$2:1/0) It should be ($3 eq 'M' ? $2 : 1/0) except that $3 is parsed as a number, not a string, so even then you don't get what you want. So I expect that it compares the third column to 'M' and on a match return the second column. Isn't that? Now I receive None-numeric string found where a numeric expression was expected. I think plot "< awk '/M$/{print $1\" \"$2}' data.txt" u 1:2 does what you want. Leo |
From: BBands <bb...@gm...> - 2013-09-03 17:30:45
|
Another way is to use the string operator: stringcolumn(3) or the shorthand strcol(3). I should have seen that to start with. John On Tue, Sep 3, 2013 at 10:16 AM, Leo Butler <l_b...@us...> wrote: > It should be ($3 eq 'M' ? $2 : 1/0) except that $3 is parsed as a > number, not a string, so even then you don't get what you want. > > So I expect that it compares the third column to 'M' and on a match return the second column. Isn't that? Now I receive > > None-numeric string found where a numeric expression was expected. > > I think > > plot "< awk '/M$/{print $1\" \"$2}' data.txt" u 1:2 > > does what you want. |
From: Mahmood N. <nt_...@ya...> - 2013-09-03 18:08:33
|
The awk command works fine. Thank you all for the effort. plot "< awk '/M$/{print $1\" \"$2}' data.txt" u 2 Regards, Mahmood ________________________________ From: BBands <bb...@gm...> To: Leo Butler <l_b...@us...>; gnuplot <gnu...@li...> Sent: Tuesday, September 3, 2013 10:00 PM Subject: Re: [Gnuplot-info] ploting if a special character exist in the line Another way is to use the string operator: stringcolumn(3) or the shorthand strcol(3). I should have seen that to start with. John On Tue, Sep 3, 2013 at 10:16 AM, Leo Butler <l_b...@us...> wrote: > It should be ($3 eq 'M' ? $2 : 1/0) except that $3 is parsed as a > number, not a string, so even then you don't get what you want. > > So I expect that it compares the third column to 'M' and on a match return the second column. Isn't that? Now I receive > > None-numeric string found where a numeric expression was expected. > > I think > > plot "< awk '/M$/{print $1\" \"$2}' data.txt" u 1:2 > > does what you want. ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk _______________________________________________ gnuplot-info mailing list gnu...@li... https://lists.sourceforge.net/lists/listinfo/gnuplot-info |
From: Leo B. <l_b...@us...> - 2013-09-03 20:23:43
|
Another way is to use the string operator: stringcolumn(3) or the shorthand strcol(3). I should have seen that to start with. Thanks, I wasn't aware of this. So you would use plot "data.txt" u 1:(strcol($3) eq 'M' ? $2 : 1/0) Leo |
From: Mahmood N. <nt_...@ya...> - 2013-09-04 05:20:33
|
I think awk is faster than strcol. Is that right? Regards, Mahmood ________________________________ From: Leo Butler <l_b...@us...> To: BBands <bb...@gm...> Cc: gnu...@li... Sent: Wednesday, September 4, 2013 12:53 AM Subject: Re: [Gnuplot-info] ploting if a special character exist in the line Another way is to use the string operator: stringcolumn(3) or the shorthand strcol(3). I should have seen that to start with. Thanks, I wasn't aware of this. So you would use plot "data.txt" u 1:(strcol($3) eq 'M' ? $2 : 1/0) Leo ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk _______________________________________________ gnuplot-info mailing list gnu...@li... https://lists.sourceforge.net/lists/listinfo/gnuplot-info |
From: BBands <bb...@gm...> - 2013-09-04 05:46:02
|
Don't know about speed, but strcol() will work where awk isn't available. jab On Tue, Sep 3, 2013 at 10:20 PM, Mahmood Naderan <nt_...@ya...> wrote: > I think awk is faster than strcol. Is that right? |
From: Ethan A M. <eam...@gm...> - 2013-09-04 05:50:32
|
On Tuesday, 03 September 2013, Mahmood Naderan wrote: > I think awk is faster than strcol. Is that right? Both awk and strcol have to actually parse the line, so I suspect if speed is the issue then plot '< grep M file' is faster than either of them. Ethan > > > > Regards, > Mahmood > > > > ________________________________ > From: Leo Butler <l_b...@us...> > To: BBands <bb...@gm...> > Cc: gnu...@li... > Sent: Wednesday, September 4, 2013 12:53 AM > Subject: Re: [Gnuplot-info] ploting if a special character exist in the line > > > > Another way is to use the string operator: stringcolumn(3) or the > shorthand strcol(3). I should have seen that to start with. > > Thanks, I wasn't aware of this. So you would use > > plot "data.txt" u 1:(strcol($3) eq 'M' ? $2 : 1/0) > > Leo > > > -- Tradition is not the worship of ashes, but the preservation of fire. - Gustav Mahler |