Skip to content

Data Extraction

mkraska edited this page Apr 1, 2022 · 8 revisions

Select Objects by Property

Given an object list:

obj: [
 ["grid","","",-1.5,6.5,-2.5,4,40],
 ["forceGen","F_2",[-0.5,3.5]],
 ["momentGen","M_2",[1.5,3.5]],
 ["beam","",[0,0],[3,0],0.15,"locked"],
 ["bar","",[3,0],[5,-1],"hide"],
 ["fix12","A",[0,0],0,"hide"],
 ["fix12","C",[5,-1],0,"show"],
 ["label","\\(B\\)",[2.8,-0.5]],
 ["q","","q_0",[0,0.3],[3,0.3],0.7,0.7,0,"show"],
 ["force","A_v",[0,0],[0,1.6],10,"active"],
 ["force","A_h",[0,0],[1.1,0],10,"active"],
 ["force","B",[3,0],[4.2,-0.6000000000000001],10,"active"]
];

and the associated names

names: [0,0,0,"locked",[12],[10,11],"show",0,"show",A_v,A_h,B];

We want to extract entries by properties:

All forces:

sublist_indices (objects, lambda ([x], x[1]="force")); results in: [10,11,12]

All active forces

sublist (objects, lambda ([x], last(x)="active" and x[1]="force")); results in [10,11,12]

length(sublist_indices (obj, lambda ([x], x[1]="force" and last(x)="active"))); results in 3.

Force B

sublist_indices (objects, lambda ([x], x[1]="force" and x[2]="B")); results in [12]

Number of forces at object with given index

num: length( sublist_indices (names[index], lambda ([x], obj[x][1]="force" ) ) ); for index=5 results in 1 and for index=6 results in 2

Indices of forces at fixed support A

names[sublist_indices (objects, lambda ([x], x[1]="fix12" and x[2]="A"))[1]]; results in [10,11]

active vertical force with name A_v

sublist_indices (objects, lambda ([x], last(x)="active" and x[1]="force" and (x[4]-x[3])[1]=0 and x[2]="A_v")); results in [10]

Tryout Space

In order to try code snippets in jsfiddle,

  1. copy the code from the wiki page to the clipboard
  2. follow the link for the JSXGraph version you want to try
  3. Replace the code in the HTML section (contents of <p hidden id="init">) with the content of the clipboard
Clone this wiki locally