Accessing a structure from a script file
Show older comments
I am using a piece of software which processes data and exports it to Matlab as a structure within a mat file. I am tryng to write a script which will extract the data for further processing using Matlab.
The software automaticaly names the structure as a variation of the filename by adding the leading character 'N'. For example the file test.mat will contain the structure with the name Ntest. The structure itself is (1xch) format where 'ch' is the number of data channels exported. and contains 10 fields giving information about the data channel. The data itself is stored as single precision vector '.data'
I have been able to access the data ok using command line instructions, but wish to make use of a script to save time. Unfortunately all examples of structures that I have come across use command line processing to access them.
I have tried loading the mat file using the commands;
[filein,pname]=uigetfile('*.*','select');
load (filein);
but cannot get a form of syntax to enable me to generate the structure name to progress further in accessing the structure itself.
Am I using the correct approach or is there a better way of accessing a structure contained within a mat file using a script ?. Any help on the correct syntax or approach would be appreciated.
Answers (3)
Sean de Wolski
on 29 Oct 2012
I would use:
S = load(filein)
So that you have the structure/variable named in a 'known' variable.
Star Strider
on 29 Oct 2012
Edited: Star Strider
on 29 Oct 2012
I'm not certain that I completely understand your problem. I suggest that you might be able to do what you want using load with an output argument, for example:
S = load(filein);
Then S should have the information you're interested in.
Chris ODonnell
on 29 Oct 2012
Edited: Chris ODonnell
on 29 Oct 2012
0 votes
1 Comment
Sean de Wolski
on 29 Oct 2012
It shouldn't be any different in a script than from the command line. If you run commands at the command line, the exact same commands should work when in a script and run essentially at the command line.
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!