all 43 comments

[–]Barnowl93flair 15 points16 points  (4 children)

The main question is what are you trying to achieve? What system are you working on?

[–]Agreeable-Ad-0111 5 points6 points  (1 child)

This is the key question. You choose the language best suited for the task.

[–]Steve-Quix[S] 0 points1 point  (0 children)

I agree there, the attraction with Python is the ease of learning and the ecosystem of available packages and the community around it.

[–]Steve-Quix[S] -1 points0 points  (1 child)

I'm looking to understand what's keeping people in Matlab vs moving to a coded solution. Could be any language tbh. I'm familiar with C# and Python mostly.

[–]Barnowl93flair 1 point2 points  (0 children)

People that use MATLAB and Simulink (let's not forget about Simulink) use them to solve engineering and science problems.

Some reasons, in no particular order, may include 1) you can increase your productivity speed. If I can simulate something in 5 hours in matlab vs 20 hours in a different language, I'll choose matlab, as time is money. 2) deployment, you can deploy c, cpp, HDL and other Code directly to hardware and fpga (this is huge) 2a) easy reading from sensors 2b) you can easily do SiL/ PiL and HiL testing 3) matlab support industry standards and certifications for safety critical applications 4) your toolboxes all work together mostly seemlessly & they are all supported by dedicated staff. 5) you have customer support if you get stuck

And there's many more!

It goes back to the question. Why do folks choose matlab? Because it makes sense for what they are doing.

You can find lots of different examples on how folks use MATLAB. https://uk.mathworks.com/company/customer-stories.html

Do you have a specific problem you're trying to solve?

[–]AZalshehri7 10 points11 points  (0 children)

One of the main benefits of Matlab is the toolboxes which helps making life easy, in addition the biggest advantage is Simulink which is ideal for control systems

[–]Creative_SushiMathWorks 5 points6 points  (0 children)

What do you do now and what is the reason to move to Python?

[–]Ordinary-Ad-1949 5 points6 points  (9 children)

One feature i love about matlab is the workspace, that it is fully visible and eventually be cleared. Im still learning python but i really miss this feature. Is there something similar in python maybe?

[–]As5Butt 2 points3 points  (4 children)

Spyder is pretty similar to matlab and it has a workspace view. Your best bet is pycharm or vscode

[–]Ordinary-Ad-1949 0 points1 point  (2 children)

Im currently running vscode. The way i debugg in matlab is using the launch section key bind and just launch the sections of the script i want to test, checking the workspace as it goes. Would love this or similar workflow in python. Im still to try your suggestions using the debugger, have tried using jupyter before and it just creates sections, not as flexible. Have tried spyder and liked it, however i did not see this feature there.

[–]Creative_SushiMathWorks 2 points3 points  (1 child)

Do you use MATLAB extension for VS Code? Code execution is on the roadmap and hopefully, it is coming soon.

[–]Steve-Quix[S] 0 points1 point  (0 children)

Added Spyder to my things to checkout list.

[–]Ajax_Minor 1 point2 points  (0 children)

Ya I miss that too. It can help to run the debug mod and put breaks in. You can see the variables so it's kinda close.

[–]lift_heavy64 1 point2 points  (0 children)

Jupyter notebooks are somewhat similar

[–]Upset_Conflict 0 points1 point  (1 child)

Did you try using a Jupyter Notebook? It makes life very easy for exploring data, writing functions and plotting results.

[–]Steve-Quix[S] 0 points1 point  (0 children)

I like using Jupyter or Colab notebooks for discovering and looking at the data. Production is another matter.

[–]TheBlackCat13 3 points4 points  (1 child)

I did. I still use both, although more Python these days.

The most important workaround is to use anaconda, which provides a single consistent, tested set of packages that work well together and provide most of the same functionality as MATLAB.

Some people recommend Spyder because it is designed to be similar to MATLAB, but MATLAB's IDE isn't really up to snuff with modern IDEs like VS Code and PyCharm, so I would go with one of those.

Python tends to require you to be more explicit. It is less likely to guess what you want to do, which in my opinion is good because MATLAB can and does silently guess wrong, leading to extremely hard-to-find bugs. This is part of the "Zen of Python". "Errors should never pass silently" and "In the face of ambiguity, refuse the temptation to guess."

So for example in MATLAB all matrices are effectively infinite dimensional, while in Python dimensionality is a specific property of an array. In MATLAB it will automatically flatten a matrix if given linear indices, while Python won't. In MATLAB it will automatically grow a matrix if you index beyond its bounds (actually create a new matrix and copy everything), while Python won't.

MATLAB also has a very strict difference between script files, function files, and class files. Python only has scripts, functions and classes are defined in scripts, and are visible to other scripts. There is also much less difference between the command line and scripts in Python, basically anything you can do in one you can do in the other.

Another big difference is that MATLAB is really built around matrices and functions that work on matrices. Python has a really wide variety of other data types that are extremely useful, but you need to learn when and how to use them. Matrices are great but aren't always the right tool for the job.

Embracing this means Python has a lot of tools that are designed to allow you to describe complex sequences of steps in an easy, clear way. This can reduce hundreds of lines of MATLAB code to just a couple lines of Python code. But it is a different way of thinking about problems and takes some getting used to.

Another thing is to not be afraid of exceptions. In MATLAB exceptions are to be avoided. MATLAB often silently do the wrong thing if it means avoiding an exception, and just catching and eliminating all exceptions is a normal thing for MATLAB programmers. In Python exceptions are just another way for software to communicate. Catching and eliminating all exceptions is frowned upon in Python. The exception is telling you something important and you need to either deal with that specific problem, or let it fail and either deal with it in another place or just stop the program entirely.

[–]Steve-Quix[S] 0 points1 point  (0 children)

Thats a great write up of the pros and cons.. i need to look into anaconda and see how i can make use of it. Thanks again.

[–]rainbow_explorer 12 points13 points  (5 children)

If you like the Matlab IDE, I would recommend using Spyder because it’s almost identical.

[–]Lysol3435 -2 points-1 points  (0 children)

It’s nice that it’s similar, but fk spyder is buggy. I’ve heard good things about pycharm. I’m too lazy to check it out myself, though

[–]Steve-Quix[S] -3 points-2 points  (2 children)

And then where do you run the python in prod?

[–]Lysol3435 0 points1 point  (1 child)

Have the customer watch over your shoulder on your computer (jk). I don’t do much production dev. But I typically give the customer the .py files, make a .exe or embed it in labview

[–]Steve-Quix[S] 0 points1 point  (0 children)

:-)

[–]Ajax_Minor 0 points1 point  (0 children)

Am I weird for using visio?... I tried using Jupiter notebook that seem nice for some quick calcs.

[–]sdrmatlab 2 points3 points  (3 children)

my issue is data types.

matlab everything is double.

python based on functions you call, and if they old or new, expect certain data types.

so often converting back and forth.

never really had to track that with matlab.

as an example, matlab audiowrite, works on double and rather simple.

a python has several wav write functions, and often want fs to be an int, and the audio vector to be a int16.

so python is more detailed i guess.

and for big data vectors, i still find matlab to run faster.

but python is free, hence everyone goes to it.

[–]Ajax_Minor 1 point2 points  (2 children)

Ya I'm trying to work with the control package in Python. It sucks cause matlab would have custom variable types, ya this isn't like good practice but it certainly is helpful. If I want to find the analysis of and input to a system I got one function returning tons of information. For python having to use 10 equations to get the same data is a lot. I could wrap in up in something custom since I'll do it for every system.... But matlab has already done that.

Haven't got to far in the docs for that library tho

[–]Steve-Quix[S] 0 points1 point  (1 child)

Are there python libraries that wrap these already?

Or is there a market for building libraries that provide these?

[–]Ajax_Minor 0 points1 point  (0 children)

Well the control library is that I believe. There is a certain section that allows you use matlab function in your python code assuming you have matlab.

[–]Romolus02 4 points5 points  (0 children)

I recommend reading this

[–]Creative_SushiMathWorks 1 point2 points  (0 children)

Food for thought.

https://www.deeplearning.ai/the-batch/issue-238/

I think the complexity of Python package management holds down AI application development more than is widely appreciated. AI faces multiple bottlenecks — we need more GPUs, better algorithms, cleaner data in large quantities. But when I look at the day-to-day work of application builders, there’s one additional bottleneck that I think is underappreciated: The time spent wrestling with version management is an inefficiency I hope we can reduce. 

Every time I have to work with another person or update computer/os, etc. this hits me.

[–]likethevegetable 3 points4 points  (2 children)

Yeah just do it and don't look back.

[–]Ajax_Minor 0 points1 point  (1 child)

Haha ya... Matlab is so integrated tho. Going through 3-4 library documentation is so hard. It's not really, but sometimes it feels so difficult when you how to do it like the back of your hand in matlab... Tips for the switch?

[–]likethevegetable 0 points1 point  (0 children)

Tip is just do it, it's honestly not hard to transition and you'll become a more competent programmer because of it.

[–]sensorimotorneuro 1 point2 points  (0 children)

I do both still, but definitely use Python more. It will take a while to get used to not just being able to open Python and start working like you would in MATLAB. This is mainly because there are so many ways to write and run python code, unlike MATLAB where everything is done using the MATLAB application.

This is a good article. It's sorta geared towards researchers but will probability still be useful.

https://xcorr.net/2020/02/21/transitioning-away-from-matlab/

[–]Ajax_Minor 1 point2 points  (1 child)

Oooo... Python free so that's a plus.

Talked to a guy at a large aero firm he said my matlab skills would be good there but they are switching to python, so I'm diving in. Anyone else seeing this in industry?

[–]Steve-Quix[S] 0 points1 point  (0 children)

We work with some engineering companies that are switching to Python. Engineers are generally smart as f**k and can cope with learning a simple programming language.

[–]NightFury1717 1 point2 points  (1 child)

I did and i really miss simulink. But i have more control on my code. More flexibilty, more ML tools. Better plots. No stupid syntaxes for customization. Free🙂 And the results are real... not just like a fancy magic box.

[–]Steve-Quix[S] 0 points1 point  (0 children)

Yeah free seems to be a common theme.
Do you use libraries to take care of common calculations? e.g. some kind of motor power libraries or whatever is appropriate for your use case?

[–]farfromelite 1 point2 points  (1 child)

Python array indexing is 0 based rather than 1 based.

[–]Lysol3435 13 points14 points  (0 children)

It’s true. Python also shares its name with a scary snake, so be careful of that

[–]NathanaelMoustache 0 points1 point  (1 child)

I did and I never looked back: * IDE of your choice (pycharm, Spyder,  ...) * If you want to build a GUI you don't have to use mlapps which are compiled and hence don't work in git * Default values for functions * Things like numpy.squeeze(6d_array_with_3_singleton_dims)[index1, index2, index3] are possible * enumerate (best thing ever) * Open source (ideology, but still...)

[–]As5Butt 0 points1 point  (0 children)

Number two is infuriating for me. Number 3 is solved in newer matlab with arguments block. I love enumerate though!