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
 dynamic array worksheet
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

g.statkute

1 Posts

Posted - 07/29/2008 :  05:46:06 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,

1)How to allocate memory dynamically for 2D array in Origin, i get "general compiler error"?
2)How to paste elements of array to a new worksheet with OriginC?
3)Is it possible to write a part of code in labTalk and use it in *.cpp file?


void DefaultSmooth() {
	
	Worksheet wks = Project.ActiveLayer();
	if(!wks) {
		out_str("no acitve workbook window to import data");
		return;
	}
	
	int RowNo = wks.GetNumRows();
	int daliklis=1;
	int n,m;
	//double m2,m1,m,p1,p2,tarp,diff;
	
	
	//memory allocation for arrays
	double v1=-70000000, v2=70000000;
	double * Gpoints, Bpoints, Fpoints;
	Gpoints=(double *)malloc(v1*v2*sizeof(double));
	Bpoints=(double *)malloc(v1*v2*sizeof(double));
	Fpoints=(double *)malloc(v1*v2*sizeof(double));

	for(m=0;m<RowNo;m++){
		for(n=0;n<2;n++){
			//printf("Enter array elements:");
			Gpoints[n][m])=0;
			Bpoints[n][m])=0;
			Fpoints[n][m])=0;
		}
	}
//some code for data manipulation,
//how to pasta data from final array Fpoints to the worksheet?
}

Iris_Bai

China
Posts

Posted - 07/30/2008 :  06:06:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
1)We don't support 2D array in OriginC since we have matrix, so you can use matrix to do the job.
2)We can use GetColumn or GetRow of matrix to get a column or a row as a vector, and then put it into Worksheet.
3)We can use LT_execute. Just like LT_execute( strCmd );

void example()
{
	//1)
	int v1=3,v2=2;
	matrix<int> m(v1,v2);    //a array of int sized v1*v2
	int ii,jj;
	for(ii=0;ii<v1;ii++)
		for(jj=0;jj<v2;jj++)
			m[ii][jj] = ii+jj;
	for(ii=0;ii<v1;ii++)
	{
		for(jj=0;jj<v2;jj++)
			printf("%d ", m[ii][jj]);
		printf("\n");
	}

	//2)
	Worksheet wks;
	wks.Create("Origin");   //new a worksheet
	Dataset ds;
	for(ii=0;ii<v2;ii++)
	{
		ds.Attach(wks,ii);   //ds is attach to the iith column of wks, ii begins from 0
		m.GetColumn( ds, ii );//get data of the iith column, and the data will be shown at the worksheet
	}
}


Edited by - Iris_Bai on 07/30/2008 9:17:58 PM
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