The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Importing Matlab variables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

nicholas.cade@crick.ac.uk

United Kingdom
2 Posts

Posted - 12/17/2018 :  09:38:01 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Operating System: OriginPro 2018b

I want to import a Matlab .mat file into a new workbook and then automatically run a script on the data.
I can see the structure of the file and the variables it contains using the Matlab import function, if I tick the "Import into Hierarchical Structure" option.
How do I then programmatically load the individual variables into e.g. new worksheets? I can click on the variable names to load them, but need to automate this.
If I do not tick the Hierarchical import option, I get a blank workbook and no option to choose the individual variables - there is a message "The file may be created by a newer version of MATLAB."
I've tried saving the .mat file with all the possible versions, which makes no difference.
Thanks

YimingChen

1609 Posts

Posted - 12/17/2018 :  12:13:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Assume you import your data in hierarchical structure, activate the worksheet, then run the following LabTalk script in Windows->Script Window:

//specify the row idx of the variable to show
idx = 2;
page.active = 1;
strFunc$ = Token(cell(idx,1)$,3,":")$;
strVar1$ =  Token(strFunc$,2,"|")$;
strVar2$ =  Token(strFunc$,3,"|")$;
matfile_UserCallback(strVar1$, strVar2$);


Also could you send us an example of your .mat file? It should be able to import without ticking the Hierarchical import option. Please send it to <tech@originlab.com> if you want us to check further. Thank you.

James
Go to Top of Page

nicholas.cade@crick.ac.uk

United Kingdom
2 Posts

Posted - 12/18/2018 :  05:34:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, but I just get a blank new worksheet appearing.
I'll send an example .mat file

quote:
Originally posted by YimingChen

Hi,

Assume you import your data in hierarchical structure, activate the worksheet, then run the following LabTalk script in Windows->Script Window:

//specify the row idx of the variable to show
idx = 2;
page.active = 1;
strFunc$ = Token(cell(idx,1)$,3,":")$;
strVar1$ =  Token(strFunc$,2,"|")$;
strVar2$ =  Token(strFunc$,3,"|")$;
matfile_UserCallback(strVar1$, strVar2$);


Also could you send us an example of your .mat file? It should be able to import without ticking the Hierarchical import option. Please send it to <tech@originlab.com> if you want us to check further. Thank you.

James

Go to Top of Page

YimingChen

1609 Posts

Posted - 12/18/2018 :  09:19:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please change last line of the script to:
OCHDF5_UserCallback(strVar1$, strVar2$);


Thanks,
James
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000