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 for Programming
 Forum for Origin C
 Reading matlab structure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

couturier

France
291 Posts

Posted - 05/16/2021 :  07:57:38 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2021b
Operating System: win10 64bit

Hi,
Are there any functions for importing a matlab structure into an OC struct or tree ?

thanks

cpyang

USA
1406 Posts

Posted - 05/16/2021 :  6:15:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Did you try the MATLAB Connector? It shows you a tree loading from the file. Is that what you need?

CP
Go to Top of Page

couturier

France
291 Posts

Posted - 05/17/2021 :  02:16:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, but I need to arrange the different parts of the data, so I'd like to access that tree in OC before putting the data into the wks
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 05/17/2021 :  12:21:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This will give you the tree,


#include <../Originlab/oMATio.h>
void dt(string strFile)
{
	Tree tr;
	int nRet = OMAT_Make_import_tree(&tr, strFile, true, NULL);
	out_int("ret=", nRet);
}



CP
Go to Top of Page

couturier

France
291 Posts

Posted - 06/03/2021 :  05:01:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks CP for that function
How can I put the data in a wks ?

void dt(string strFile)
{
	Tree tr;
	int nRet = OMAT_Make_import_tree(&tr, strFile, true, NULL);
	
	matrix mm;
	mm = tr.Fs2Fs_EMGinterpol_optiHz_norm._11._11.dVals2; // ---> returns bad storage method variable type
	
	Worksheet wks;
	wks.Create("Origin");  // Create a new worksheet
	mm.CopyTo(wks, 0, 0, -1, -1, 0, 0, FALSE, TRUE);  // Convert the data to worksheet
}


it returns bad storage method variable type
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/03/2021 :  1:00:54 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That tree is only the structure, it does not have actual values.

In order to read the data, we will need to give you sample code on using the MATLAB connector from OC.

CP
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/03/2021 :  5:31:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The following code read a matrix stack to a matrix sheet and copy one of the matrix into a worksheet

void mdc(string strpath)
{
	MatrixPage mp;
	mp.Create("Origin", CREATE_HIDDEN);
	//add matlab connector to the matrix book
	mp.DoMethod("dc.Add", "MATLAB");
	MatrixLayer ml = mp.Layers();
	//setup the connection
	ml.SetProp("dc.Source", strpath);
	//set the selection path into the structure
	ml.SetProp("dc.Sel", "MATLAB/Fs2Fs_EMGinterpol_optiHz_norm");
	//this is to execute the actual import
	ml.DoMethod("dc.import");
	//you can remove the connector after import
	mp.DoMethod("dc.remove");

	//pick one of the matrix and transfer to a worksheet
	MatrixObject mobj = ml.MatrixObjects(4);

	WorksheetPage wp;
	wp.Create("Origin");
	Worksheet wks = wp.Layers();
	matrixbase& mb = mobj.GetDataObject();
	mb.CopyTo(wks, 0, 0, -1, -1, 0, 0, false, false);
}


I recommend that you play with the connector from GUI too
1. New Matrix
2. Data > Connect to File > Matlab

CP
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