Search code examples
octave

Access error in tablicious package in octave when using 'subsetrows' and 'subsetvars' methods


I am creating tables in octave using 'Tablicious' package. Table is created fine, but when I am trying to filter rows or columns using 'subsetrows' or 'subsetvars' I am getting an access error.

pkg load tablicious

# Data
Table = {'Length', 'Force', 'Max_force'};
Length = [100; 125; 160; 200; 250; 315; 400; 500; 630; 720; 800; 1000];
Force = [250; 300; 300; 350; 400; 400; 400; 400; 400; 400; 400; 400];
Max_force = [500; 600; 600; 700; 800; 800; 1000; 1000; 1000; 1000; 1000; 1000];

# Create table
tab = table(Length, Force, Max_force);
prettyprint ( subsetrows(tab, : ) )

Here is the error that I am getting

error: : method 'subsetrows' has private access and cannot be run in this context
error: called from
    Tablicious_table_practice at line 12 column 1

How do I filter my table data like in SQL?


Solution

  • It seems that subsetrows is a private variable. Its role is to implement internally the 'subsetting' operations for the table.

    This means that you can use ordinary indexing / subscripts / ranges, like in normal arrays:

    octave:10> prettyprint ( tab(:,:) )
    ------------------------------
    | Length | Force | Max_force |
    ------------------------------
    | 100    | 250   | 500       |
    | 125    | 300   | 600       |
    | 160    | 300   | 600       |
    | 200    | 350   | 700       |
    | 250    | 400   | 800       |
    | 315    | 400   | 800       |
    | 400    | 400   | 1000      |
    | 500    | 400   | 1000      |
    | 630    | 400   | 1000      |
    | 720    | 400   | 1000      |
    | 800    | 400   | 1000      |
    | 1000   | 400   | 1000      |
    ------------------------------
    
    octave:11> prettyprint ( tab(3:6, :) )
    ------------------------------
    | Length | Force | Max_force |
    ------------------------------
    | 160    | 300   | 600       |
    | 200    | 350   | 700       |
    | 250    | 400   | 800       |
    | 315    | 400   | 800       |
    ------------------------------
    
    octave:12> prettyprint ( tab(3:6, {'Max_force', 'Length'} ) )
    ----------------------
    | Max_force | Length |
    ----------------------
    | 600       | 160    |
    | 700       | 200    |
    | 800       | 250    |
    | 800       | 315    |
    ----------------------