473,324 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Vector of non-primitive objects : structs

1
Hi, I am a beginner in C++ so I hope you can be patient on me since my purpose is to learn.

I am now involved in a relatively complicated Data Analysis exercise.

I have a series of frames (vehicle data: trajectory) and I need to extract from them given informations.

For that, I put the info of each frame in a struct.
And I want to store the structs into a first vector grouped based on 1 info: time (ps: all the structs/frames of this vector have the same time).
This vector will be a part of another struct frame_time.
and this mother struct will be stored in itself based on increasing time (another attribute of the frame).

After that, I can sort the frames in the minor vector (location) based on the location info:

I created the following code (this is only part of the program):
Expand|Select|Wrap|Line Numbers
  1. FrameTimeData frame_time_data;
  2.  
  3. for (int i = 0; i<NumberOfFrames; i++)
  4. {
  5.     VehFrameData veh_frame_data;
  6.     veh_frame_data = FrameLocationInitial[i]; //vector of frames already arranged 
  7. //based on time and sorted accordingly: just need to read them and then 
  8. //classify them in different mother structs stored themselves in a vector
  9.     frame_time_data.FrameLocation.push_back(veh_frame_data);
  10.     if (FrameLocationInitial[i].time != FrameLocationInitial[i+1].time)
  11.     {
  12.         FrameTime.push_back(frame_time_data);
  13.         FrameTimeData frame_time_data;
  14.     }
  15.  
  16. }
  17.  
The problem I am having is that each frame_time_data struct is taking the whole vector of FrameLocation from the first term and not just from the frame where time has changed. Any ideas or easy suggestions.

Regards
Mar 22 '07 #1
1 2259
weaknessforcats
9,208 Expert Mod 8TB
Consider a vector of vectors:

vector< vector<MyStruct> > v;

Each element of v it itself a vector<MyClass>. These vector<MyClass> elements are the vectors whose elements have the same time. Therefore all you need do is sort v to have everything in time sequence.

Write a comparision function as a binary predicate to compare your vector<MyClass> elements and call the std::sort algorithm.

This avoids the "mother of all structs" approach.
Mar 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Richard Thompson | last post by:
I've got a memory overwrite problem, and it looks as if a vector has been moved, even though I haven't inserted or deleted any elements in it. Is this possible? In other words, are there any...
3
by: koperenkogel | last post by:
Dear cpp-ians, I have a vector of structures: struct meta_group { float id; float num; float mean; float sum;
9
by: uotani.arisa | last post by:
Hi, Can someone tell me how to declare a pointer to a vector of pointers? I'm just not sure how to do this... I've tried essentially the following: vector<string *> * v; ....
4
by: Varun Kacholia | last post by:
Hi everyone, I have the following piece of code: vector<MyClass*> my_vector(10, NULL); However this throws the following errors: myfile.cc: warning: converting NULL to non-pointer type...
9
by: Someonekicked | last post by:
In my program, I need to open multiple files, and I wont know till after the program execution how many of them (user will enter that value). So I am using a vector of fstream. I am using fstream...
4
by: lutorm | last post by:
Hi all, I'm having a problem writing template functions that take vector<T>::iterator as arguments and I'm sure you guys can set me straight. Like this: #include<vector> using namespace std; ...
4
by: arnuld | last post by:
i wrote a programme to create a vector of 5 elements (0 to 4), here is the code & output: #include <iostream> #include <vector> int main() { std::vector<intivec; // dynamically create a...
1
by: atomik.fungus | last post by:
Hi, I'm re-writting my matrix class to practice my programming and the computer doesn't let me compile the next code: ( this example come from the constructor of the class) //the matrix is made...
12
by: y-man | last post by:
Hi, I am creating a child class of the vector, which contains a couple of functions to make the work with carthesian coordinate vectors easier. To make things work more easily, I would like to...
5
by: barcaroller | last post by:
Is there a way of getting a C-style pointer to the contents of a vector<T> (similar to string's c_str)? If not, what is the most efficent way of doing this? The reason I need a C-style pointer...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.