I am getting row data from a sensor (distances & amplitude) and saving them into a vector container in C++.
Using OpenGL, I am visualizing it(see the pic below)
Now I want to split the data based on some factors(for clustering purpose) and want to save them into new individual vector(s).
The problem is, I don't know how many cluster I'll get, so no idea about the number of vector(s) I'll need.
Anybody know any method for this, please share.
Asked
Active
Viewed 60 times
-1
Harsh Patel
- 187
- 9
-
5So use a vector of vectors then? – Some programmer dude Oct 04 '16 at 15:04
-
No, don't do that. Use a vector and map 2D indexing on top as a view. – Lightness Races in Orbit Oct 04 '16 at 15:13
1 Answers
1
This sounds like a vector of vector.
// Vector of vector that will contain all your clusters
std::vector<std::vector<DATA>> clusters;
// everytime you have a new cluster you can then do something like :
std::vector<DATA> currentCluster;
// You add the data to the cluster
currentCluster.emplace_back(/* The data */)
// You then add the currentCluster to the group of clusters.
clusters.emplace_back(currentCluster);
Scriptodude
- 93
- 7
-
-
Nope i didn't see joachim's comment while i was typing this answer ^^ – Scriptodude Oct 04 '16 at 15:12
-
http://stackoverflow.com/questions/4303513/push-back-vs-emplace-back i don't know if he's using the c++0x norm, so they are strictly equivalent in the c++98 standard. – Scriptodude Oct 04 '16 at 15:13
-
This is very inefficient for a number of reasons. Better: a 2D view over a single-dimension `vector`. – Lightness Races in Orbit Oct 04 '16 at 15:13
-
@Scriptodude: In C++98, how can they be equivalent when one doesn't exist lol – Lightness Races in Orbit Oct 04 '16 at 15:14