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

Scomex

France
5 Posts

Posted - 02/27/2013 :  12:25:56 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 8.0.63.988 SR6 (8.0988)
Operating System: Windows 7

Hi,
I am a novice in programing, whether it is Origin C or else. My problem is the following. I would like to dynamically name vectors, according to the index ii of a for loop, for instance, because the number of vectors will not be the same each time I will use my program. I have to create them first before I call them one by one. If it is possible, I would like to know if I can use a single reference for all of these vectors.
My aim is to do something like :

for(ii=0;ii<nb;i++)
{
vector vec"ii"(0) //create the vector with a name according the index ii
}
//At this stage, I would have : vec0, vec1, vec2, ..., vec(n-1). Then :
for(ii=0;ii<nb;i++)
{
vector vec=vec"ii"
vec=...
}
I have to point out that I can't "merge" the two loops... Hope my request is clear. Thank you in advance !

Penn

China
644 Posts

Posted - 02/27/2013 :  9:22:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I am afraid you cannot use like this way. However, you can use the Array class. For example

Array<vector&> arr(true);  // declare an array for vector
for(int ii = 0; ii < nb; ii++)  // add nb vectors to the array
{
	vector *vv = new vector();  // pointer to a vector
	vv->Add(ii+10.0);  // do something with the vector
	arr.Add(*vv);  // add to array
}

for(ii = 0; ii < nb; ii++)
{
	vector& v = arr.GetAt(ii);  // get vector from array
	printf("%f\n", v[0]);  // do something...
}


Penn
Go to Top of Page

Scomex

France
5 Posts

Posted - 03/04/2013 :  05:40:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you for your help. This is what I wanted to do.
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