Accessing a structure from a script file

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.

回答 (3 件)

Sean de Wolski
Sean de Wolski 2012 年 10 月 29 日

0 投票

I would use:
S = load(filein)
So that you have the structure/variable named in a 'known' variable.
Star Strider
Star Strider 2012 年 10 月 29 日
編集済み: Star Strider 2012 年 10 月 29 日

0 投票

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
Chris ODonnell 2012 年 10 月 29 日
編集済み: Chris ODonnell 2012 年 10 月 29 日

0 投票

Thanks for the responses guys. Perhaps I wasn't clear what I'm trying to do.
I can ineteractively load the data into the memory using the commands
load test.mat;
x=Ntest(1,1).data;
y=Ntest(1,2).data;
etc What I would like to do is load the file using load(filein); then generate the name of the structure 'Ntest' in a way that I can access the data sets in the manner that I can do from the command line.

1 件のコメント

Sean de Wolski
Sean de Wolski 2012 年 10 月 29 日
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Import and Analysis についてさらに検索

質問済み:

2012 年 10 月 29 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by