Accessing variable by string name
I need to load experimental data into scicoslab, a (pretty badly designed) clone fork of scilab which happens to support graphical modeling. The documentation on the web is pretty poor, but it's reasonably similar to scilab and octave.
The data I need to process is contained into a certain number of text files:
Data_100. Each of them can be loaded using the -ascii flag for the
The problem comes from the fact that
loadmatfile("foo", "-ascii") loads the file
foo.mat into a variable named
foo. In order to to cycle on the data files, I would need to do something like:
for i = [5:5:100] name = sprintf("Data_%02d", i); loadmatfile(name, "-ascii"); x = read_var_from_name(name); do_something(x); end
where what I search for is a builtin
read_var_from_name which would allow me to access the internal symbol table by string.
Do you know if there exist a similar function?
- There's no way of overriding this behavior if your file is in ascii format;
- In this phase I could also use octave (no graphical modelling is involved), although it behaves in the same way.
>> foo = 3.14; name = 'foo'; eval(name) foo = 3.1400
The above works in MATLAB, and Scilab's documentation says it also has an
eval function. Not sure if I understood you correctly, though.
Access variable by string name?, Let's say I have a variable named myVar. I want to call it using the string "myVar". Other than setting up hashtables ahead of time, does anyone. The name of a variable can be stored in another variable, allowing it to be accessed dynamically. Such variables are known as variable variables. To turn a variable into a variable variable, you put an extra $ put in front of your variable.
@arne.b has a good answer.
In your case you can also do that in matlab:
Variable variables - Manual, Class properties may also be accessed using variable property names. Note that normal variable variables will not be parsed in double-quoted strings. You'll� 2 Accessing Tree Variable; Get Project Variables. Minimum Origin Version Required: Origin 8.1 SR0 // project string variable name vector < string
lets go through your points one by one:
- "ScicosLab, a (pretty badly designed) clone of Scilab" This in my opinion is an inaccurate way of introducing the software. ScicosLab is not a clone of Scilab but a fork of it. The team behind ScicosLab (INRIA) are the ones who made scocos (now called xcos in Scilab development line). At some point (from Scilab v4) the Scilab team decided to move away from Tcl/tk towards Java, but the SciccosLab/scicos team departed, keep using the language (Tcl) and it's graphical user interface design package (tk). Giving the ScocosLab community the credit that the whole Scilab documentation and support is not very good in general. :) (more about Scilab and the forks here)
- Regarding the technical question I'm not sure what you are trying to achieve here, Scilab/ScicosLab still have the
evalfunction which basically does what you want. However this function is to be deprecated in favor of
evstr. There is also the
execstrfunction which worth studying.
loadmatfile, as far as I have understood, "tries" to load the variables defined in a MATLAB
.matfile (MATLAB's proprietary tabular format) into the Scilab workspace. For example if there is a variable
fooit will "try" to create the variable
fooand loads its value from the MATLAB script. Check this example. I would create a variable
x(i) = fooin the for loop. again your question is not completely clear.
- As a side note maybe you could consider exporting your data as CSV instead of
Variables, Variables store values so that those values can be accessed in code later. Inside a double-quoted string, surround the name of the variable (the portion after � Access variable by string name? Discussion in 'Scripting' started by tonyd, Mar 2, 2010. tonyd. Joined: Jun 2, 2009 Posts: 1,224. Let's say I have a variable named myVar.
14.1 – Accessing Global Variables with Dynamic Names, 14.1 – Accessing Global Variables with Dynamic Names v = _G -- start with the table of globals for w in string.gfind(f, "[%w_]+") do v = v[w] end return v end A variable in single quotes ' is treated as a literal string, and not as a variable. Variables in quotation marks " are treated as variables. To get the value held in a variable, you have to provide the dollar sign $. A variable without the dollar sign $ only provides the name of the variable.
How can I get the name of a MATLAB variable as a string , I would like to convert the name of my MATLAB variable to a string so that, Now you can access the name of the data, but are not restricted to specific names� when your in dataflow, and when you put that script component, rt click, in script tab, u can see custome properties, read write variables, click on the ellipse and check the variable. in may case @variable2 is a write variable. also go to input columns and check the varialbe you want to read in y case @variable1 is a read variable.
How to convert string to variable name ?, Learn more about char, variable, bad idea. through better code design is always preferred to writing slow, buggy, hack code accessing variable names. const variable = object[property_name] object[property_name] = value; This does the exact same thing as the previous example. document['createElement']('pre') A space before bracket notation is allowed. document ['createElement']('pre') Property names. Property names are string or Symbol. Any other value, including a number, is coerced to a string.