In Matlab, we can get the max, min, and also the position of the complex vector:
[mag_x idx_x] = max(abs(X));
[mag_y idx_y] = max(abs(Y));
I know that we can do the similar with C++ because Matlab is build from C++. But I could not figure it out. I also have incomplete code, and still working on it:
#include <iostream> // std::cout
#include <algorithm> // std::min_element, std::max_element
#include <vector>
#include <complex>
#include <iostream>
int main()
{
//typedef std::complex < double > C
vector <complex<short> > vec;
vec.push_back ( complex <short> (1,1));
vec.push_back ( complex <short> (1,2));
vec.push_back ( complex <short> (3,4));
vec.push_back ( complex <short> (0,0));
vec.push_back ( complex <short> (4,8));
vec.push_back ( complex <short> (0,0));
vec.push_back ( complex <short> (2,3));
vec.push_back ( complex <short> (1,1));
int size = sizeof(x_vec)/sizeof(x_vec[0]);
for(int i =0; i < size; i++)
{
cout << x_vec[i] << endl;
}
...
return 0;
}
I also look at the sample code from this link: http://www.cplusplus.com/reference/algorithm/max_element/ but it work only for vector.
Also when I calculate the size = sizeof(x_vec)/sizeof(x_vec[0]);
I am expecting size = 8 (because of 8 vector complex above) but I gave me only size = 6.