MATLAB to Python Code conversion (NumPy, SciPy, MatplotLib?)

后端 未结 3 1102
青春惊慌失措
青春惊慌失措 2021-01-06 09:22

I\'m trying to convert the following code to Python from MATLAB for an EEG Project (partly because Python\'s slightly cheaper!)

Hopefully someone can point me in the

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-06 10:02

    Um... lots of things.

    Python has no end keyword, so you clearly need to read more about Python's syntax.

    Python arrays and slices are indexed with [] not (). Ranges are expressed as range(0,10) for example, but slices in the Matlab sense only exist in extension packages like numpy and each one has its own interface.

    Yes, you want to use matplotlib for plotting, it has pretty much the same capabilities as Matlab's plotting interface, at least at this level.

    It looks like you're guessing that Python will have the same method names as Matlab in some random package. This is not a good plan. Instead, look up the Matlab method in its documentation, which is online, find out exactly what it does, and then read into the Python package documentation for a method that does what you want. This may not exist, but I'm betting that in a program this simple, most of the ones you need will.

    The most important thing you need to understand in converting any Matlab code to other languages is the way Matlab arrays work, which is extremely unusual (but excellent for its target applications). Numpy has about the same capabilities, but a completely different notation for them.

    The serial module has already given you an open file object on the port, so you don't need the fopen.

    I think you need to spend a LOT of time with the documentation for both Python and Matlab, because it's quite clear you understand neither at the moment.

    Don't let me discourage you, I'm just being honest about where you're at.

提交回复
热议问题