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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 dynamic vector name

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Scomex Posted - 02/27/2013 : 12:25:56 PM
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 !
2   L A T E S T    R E P L I E S    (Newest First)
Scomex Posted - 03/04/2013 : 05:40:01 AM
Thank you for your help. This is what I wanted to do.
Penn Posted - 02/27/2013 : 9:22:55 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000