I have c++ function whose the only argument is an array. Also I have a matrix. How can I pass say third column of this matrix as a array into the function without creating a mediated array in the loop.
Is there c++ analogue of M(:,3) existing in MATLAB and Fortran?
Maybe you'd simply be better off using MATLAB or Fortran. :icon_rolleyes: While it's possible to shoehorn behavior from other languages into C++ with specialized libraries, the results are often (if not always) sub-optimal. Your best bet with C++ is writing code to work with the language rather than fight it.
Unfortunately or fortunately, c++ language have another features which are not contained in MATLAB or Fortran. An example is popen function for Linux. However, I think c++ is not most universal programming language. More universal one is math. Other languages try to realize matrix data manipulation in correspondence with matrix theory. c++ is a little bit odd in this regard. )
>>Other languages try to realize matrix data manipulation in correspondence with matrix theory. c++ is a little bit odd in this regard.
Well, C++ does not try to realize matrix data manipulation at all. So, it is not surprising if it seems odd to you. Languages like Fortran and Matlab are two examples of languages which were built with the explicit intent of realizing matrix operations naturally (Fortran did not succeed much in that regard, although it is used a lot and has many legacy and well-optimized code for numerical analysis in general). But, you pay for everything in programming. Matlab is very nice, natural and optimized for doing matrix operations, but it quickly gets awkward when you move away from matrix numerical analysis. C++ is probably the most universal programming language, which also means that it has to please a whole lot of people doing many different things. And not everyone is doing matrix operations, or numerical analysis, or anything related to math for that matter. If you try to provide nice built-in features to please everyone, you end-up pleasing no-one (e.g. Java). The approach in C++ is to provide only the most incontestably useful functionality in its standard libraries and then provide unparalleled language features to allow the development of awesome libraries for special purposes.
And so, to the point, there are plenty of nice open-source libraries for matrix operations. They range from very easy-to-use (often resembling Matlab) to extremely optimized and robust (often old cryptic libraries like LAPACK, or not as easy-to-use libraries based on OpenCL or OpenMP which are highly optimized and run in parallel). There is plenty of choice for this in C++. But, I guess for your purpose, that could be overkill.
Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...