Hi guys,
the title says it all, I have produced list of numbers from a c++ program into an excel file, and I want to make a CDF graph out of it. What I know is that I need to find numbers greater than zero, then number greater than one and so... but when I looked at it, I figured out that I cannot have like 50 if condition in the program to check that. So, if anybody got a theory on how to do it, I will appreciate it if he shared it with me!!
- 2 Contributors
- forum1 Reply
- 54 Views
- 6 Years Discussion Span
- comment Latest Post by deceptikon
deceptikon 1,790
the title says it all
If by "says it all" you mean that it says one can ignore your thread due to lack of information, I'd agree. :D Since I know jack squat about CDF, I'll just try to answer what I think is your question.
What I know is that I need to find numbers greater than zero, then number greater than one and so... but when I looked at it, I figured out that I cannot have like 50 if condition in the program to check that.
You can use a counted loop where the counter is the exclusive lower bound of numbers you're looking for:
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <random>
#include <vector>
#include <ctime>
using namespace std;
int main()
{
// Get a list of random numbers with possible negatives
//
auto rgen = bind(
uniform_int_distribution<int>(-99, 99),
mt19937((unsigned)time(nullptr)));
vector<int> v;
generate_n(back_inserter(v), 10, rgen);
// Find the numbers greater than any given value in the range
//
int ubound = *max_element(v.begin(), v.end());
vector<vector<int>> distribution(ubound);
for (int i = 0; i != ubound; i++)
{
for_each(v.begin(), v.end(), [&](int x)
{
if (x > i)
{
distribution[i].push_back(x);
}
});
}
// Display the raw results
//
for_each(distribution.begin(), distribution.end(), [](vector<int> x)
{
if (!x.empty())
{
copy(x.begin(), x.end(), ostream_iterator<int>(cout, " "));
cout << endl;
}
});
}
Edited
by deceptikon: n/a