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

HelpMePlease

USA
2 Posts

Posted - 08/24/2014 :  4:57:22 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I'm using origin 9.0 and have found myself in a situation where I need to use something like vector.push_back() function (as with normal c/c++). Am I missing something or is there no support for a function like this in origin? I've looked at the header file but haven't been able to find a useful alternative. Is there a way to at least dynamically allocate space for a vector so as to avoid using the SetSize() function?

Not having something like this seems to defeat the whole point of using vectors! We might as well just use arrays (which can't be avoided in origin since most arguments for data objects take in vectors).

Thanks in advance for any advice/help!


Edited by - HelpMePlease on 08/24/2014 4:58:28 PM

jasonzhao

China
262 Posts

Posted - 08/25/2014 :  06:28:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

You can refer to http://www.originlab.com/doc/OriginC/ref/vector and http://www.originlab.com/doc/OriginC/ref/vector-Add which can construct a dynamically allocated and sized array.

The following examples shows the way to assign data to a column by Vector and add extra elements to it.

#include <Origin.h>
void main()
{
Worksheet wks;
wks.Create("Origin");

 		

vector<double> vX(10);           // vX has 10 elements
for(int ii = 0; ii < 10; ii++)
        vX[ii] = ii;
for(int jj = 0; jj < 10; jj++)  // add extra 10 elements
    {double d = jj; 
      vX.Add(d);}

 Dataset dsA;   // Create Origin C Dataset		
dsA.Attach(wks,0); // Attach Origin C Dataset object dsA to Origin data set wks(0)	

dsA=vX;
}


Best regards,
Jason Zhao
OriginLab Tech Service

Edited by - jasonzhao on 08/25/2014 06:30:12 AM
Go to Top of Page

HelpMePlease

USA
2 Posts

Posted - 08/25/2014 :  9:18:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ah this is exactly what i needed.


Thanks so much!

Using Origin 9
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