Search code examples
c++matlabplotdynamic-allocation

code from matlab into c++


Is there any best approach or template to follow, while doing this? I mean two things in particular, because for me it is problematic to imagine how it would go in c++:

  • expanding arrays on go, where they are expanded during program and i dont know whethere the final size will be e.g. 10 or 100000.
  • plots. I have never done any plot in c++ as I always have been doing it in matlab when necessary.

So what templates or rules should I follow, and how could I cope with those two things? I found that eigen library would be useful for matrices (dynamically expanding also?), but as I am not sure, want to ask first to be sure of a right approach. Nothing i know about plots.

Please add some link for me to learn from, if useful. Thanks!


Solution

    • expanding arrays on go, where they are expanded during program and i dont know whethere the final size will be e.g. 10 or 100000.

    The solution to this is simple: look up std::vector (or std::deque) both provide this behaviour. (With "subtle" differences between a deque and a vector).

    • plots. I have never done any plot in c++ as I always have been doing it in matlab when necessary.

    For this you'll have to search for a library that can do this, first you'll have to look into a graphical window library such as Qt. And then you'll have to look up some library that can plot data in a graph form.
    Though for this matlab will probably always be the "easier/better" choice; C++ has nothing to help you with this.

    Also remember: first learn the language, then learn libraries!