Scenario:
For signal processing analysis, I’m receiving data from somebody else. My standard practice if I have several data files, each representing a chunk of time, is to name the data vector 'data' and the time vector 'time' and not individuate each variable name, since they are isolated by files. If I need to individuate them, I do it in the program that calls them.
However, I’ve recieved data from somebody who individuates them, so each variable is uniquely named, 'data10', 'data11'.
All my routines and programs call on 'data'. Is there a way to change these variable names from 'dataxx' to 'data' without using eval? My first thought was to try the assignin function, but it doesn’t accept wildcard arguments for the 'value' input. Each time I load a file separately in its own structure, so it will never be a problem to use a wild card, ther will always only be one file that starts with 'data...'
Thanks!
If you’re loading these variables from a
.mat-file, you can use theloadcommand with an output:collectedDatahas a field for each variable contained in the.mat-file. If you now want to access the variabledata10, you can use dynamic field names to access it:It is worth noting that
structfuncan be quite useful if you want to apply a function to each field of a structure without looping across field names.