data cut-and-paste on Octave commandline

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

data cut-and-paste on Octave commandline

Przemek Klosowski-7
Often I'd like to process some tabular data from other apps (browser or
spreadsheet). It's easy enough to mark the entire table, but the
multiple numbers on each row often seem to be delimited by tabs. When
this is dropped into Octave command line after the opening stanza of the
form 'myvar=[' , the tabs are eaten by readline, and the individual
numbers run together.

With spreadsheet, I usually can cut and paste individual columns
one-by-one, but this doesn't work for tabular data from other sources.

Is there  a better way to feed data to Octave?

If not, is there a way to temporarily turn off/disable readline processing?




Reply | Threaded
Open this post in threaded view
|

Re: data cut-and-paste on Octave commandline

Mike Miller-4
On Fri, Jul 12, 2019 at 13:19:37 -0400, Przemek Klosowski wrote:

> Often I'd like to process some tabular data from other apps (browser or
> spreadsheet). It's easy enough to mark the entire table, but the multiple
> numbers on each row often seem to be delimited by tabs. When this is dropped
> into Octave command line after the opening stanza of the form 'myvar=[' ,
> the tabs are eaten by readline, and the individual numbers run together.
>
> With spreadsheet, I usually can cut and paste individual columns one-by-one,
> but this doesn't work for tabular data from other sources.
>
> Is there  a better way to feed data to Octave?
>
> If not, is there a way to temporarily turn off/disable readline processing?
Yes, you are looking for the readline option "enable-bracketed-paste".
Add

    set enable-bracketed-paste on

to your ~/.inputrc and it should be taken care of automatically if you
are using any common terminal emulator that supports this feature.

Unfortunately, the Octave GUI terminal does *not* currently support
bracketed paste, so if you enable this option and use the GUI, you will
see a bunch of error messages about unrecognized escape sequences.

--
mike



signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: data cut-and-paste on Octave commandline

tmac017
I'm not sure what format you are pulling in but if your tabular data can be read as a text file try this. 
x = textread('new.txt','%s','delimiter','\t')
x =
{
  [1,1] = some data
  [2,1] = 2,3,4,5,6
  [3,1] = other data
}

new.txt was just a single line of text in notepad "some data (TAB) 2,3,4,5,6 (TAB) other data"

You can then use textscan on individual cells to further  deliminate your data. 
Ex. 
y = textscan(x{2}, '%s', 'delimiter',','); y = y{1}
y =
{
  [1,1] = 2
  [2,1] = 3
  [3,1] = 4
  [4,1] = 5
  [5,1] = 6
}

then store it in another format (like double)
for istep = 1:length(y) ynum(istep) = str2double(y{istep}); endfor

However, it's computationally heavy to reformat your data line by line like in a for loop so if you have to do a lot of data I would recommend using textread and textscan to deliminate your headers search your headers for the row and columns that you want to analyze then use dlmread to pull in the numerical data. 


On Fri, Jul 12, 2019 at 10:38 AM Mike Miller <[hidden email]> wrote:
On Fri, Jul 12, 2019 at 13:19:37 -0400, Przemek Klosowski wrote:
> Often I'd like to process some tabular data from other apps (browser or
> spreadsheet). It's easy enough to mark the entire table, but the multiple
> numbers on each row often seem to be delimited by tabs. When this is dropped
> into Octave command line after the opening stanza of the form 'myvar=[' ,
> the tabs are eaten by readline, and the individual numbers run together.
>
> With spreadsheet, I usually can cut and paste individual columns one-by-one,
> but this doesn't work for tabular data from other sources.
>
> Is there  a better way to feed data to Octave?
>
> If not, is there a way to temporarily turn off/disable readline processing?

Yes, you are looking for the readline option "enable-bracketed-paste".
Add

    set enable-bracketed-paste on

to your ~/.inputrc and it should be taken care of automatically if you
are using any common terminal emulator that supports this feature.

Unfortunately, the Octave GUI terminal does *not* currently support
bracketed paste, so if you enable this option and use the GUI, you will
see a bunch of error messages about unrecognized escape sequences.

--
mike



Reply | Threaded
Open this post in threaded view
|

Re: data cut-and-paste on Octave commandline

Przemek Klosowski-7
On 7/16/19 3:15 PM, Tommy McCann wrote:
I'm not sure what format you are pulling in but if your tabular data can be read as a text file try this. 
x = textread('new.txt','%s','delimiter','\t')

My question was in the context of ad-hoc calculations, using data quickly pulled out of other programs running on my desktop---cut from one application, paste into Octave, calculate/plot. I wanted to avoid having to go through other programs like editors and such.

Thanks to Mike for pointing out this Readline functionality that works great in all environments I care about:


Yes, you are looking for the readline option "enable-bracketed-paste".
Add

    set enable-bracketed-paste on

to your ~/.inputrc and it should be taken care of automatically if you
are using any common terminal emulator that supports this feature.



Reply | Threaded
Open this post in threaded view
|

Re: data cut-and-paste on Octave commandline

PhilipNienhuis
In reply to this post by Mike Miller-4
Mike Miller-4 wrote

> On Fri, Jul 12, 2019 at 13:19:37 -0400, Przemek Klosowski wrote:
>> Often I'd like to process some tabular data from other apps (browser or
>> spreadsheet). It's easy enough to mark the entire table, but the multiple
>> numbers on each row often seem to be delimited by tabs. When this is
>> dropped
>> into Octave command line after the opening stanza of the form 'myvar=[' ,
>> the tabs are eaten by readline, and the individual numbers run together.
>>
>> With spreadsheet, I usually can cut and paste individual columns
>> one-by-one,
>> but this doesn't work for tabular data from other sources.
>>
>> Is there  a better way to feed data to Octave?
>>
>> If not, is there a way to temporarily turn off/disable readline
>> processing?
>
> Yes, you are looking for the readline option "enable-bracketed-paste".
> Add
>
>     set enable-bracketed-paste on
>
> to your ~/.inputrc and it should be taken care of automatically if you
> are using any common terminal emulator that supports this feature.
>
> Unfortunately, the Octave GUI terminal does *not* currently support
> bracketed paste, so if you enable this option and use the GUI, you will
> see a bunch of error messages about unrecognized escape sequences.

That's one thing the Variable Editor was made for.
You need to first open some variable in the V.E. and select a cell but then
pasting data works perfectly.

Philip



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html