You are now following this channel
- You will see updates in your content feed.
- You may receive emails, depending on your notification preferences.
You are now following this topic
- You will see updates in your content feed.
- You may receive emails, depending on your notification preferences.
What parts of MATLAB would you not miss?
Are there parts of MATLAB that could disappear as far as you were concerned, things you don't need or which were "bad ideas" or which cause more trouble than they are worth in your experience?
One suggestion per answer please, so we can see how other people feel about the same matters.
94 Comments
Tim Harmon: Depending on your license and what you need to use MATLAB to do, this may be possible. See MATLAB Online.
Installing MatLab
\
Admin permission required to install python API. No other python modules I have ever used require this:
https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html?s_tid=srchtitle
Now that I've been forced into Linux at work, I wouldn't miss ls for a minute. It behaves horribly compared to in Windows, and means my code is not cross platform.
I've spent the last 2 days replacing every instance with
a = dir();
a = {a.name}';
Commenting on another answer just reminded me of something else:
eval(...)
Ok, I'll be honest. There's that one time I just couldn't do anything else, but I hate myself everyday for caving into eval. I would miss it just a little bit, but I would actually feel better if it was gone.
Since R2022a str2num provides a switch to only allow basic operations. It should have been the default, but suddenly there is a way to use str2num without opening a gaping hole in your program:
str2num('[1 2;3 4]',Evaluation='restricted')
ans = 2×2
1 2
3 4
str2num('disp("I''m a trickster!")',Evaluation='restricted')
ans =
[]
There is a niche of programs intended to graph (or do root solving) of user-supplied equations. Some of those are just homework assignments, but some of them are serious tutorial work or convenience graphics calculators.
In those cases, it can be difficult to resist using eval(). str2func() does help but it does not always work, and when I use it I still feel nausea to some extent as I know that I haven't done the slightest thing to prevent the security risks.
There is need for a "sandbox" function that can evaluate untrusted code (especially given as string) in a safe environment that does not allow file output and only allows file input of files the caller of sandbox specifically injects into the sandbox (which, sigh, people would tend to do without verification of trust.)
And now for my own "wouldn't miss it" feature:
finish.m
I have never used it, have never considered using it or thought it might be a solution to my problem, and haven't heard of a good use for it. Except the one guy that used it in some coworker-trolling code.
Honestly, ability to use old releases is almost on my list of wish it wasn't possible.
I know R2007a was a popular "cracked" version, haven't heard anything since then, but haven't researched it either.
I can imagine professors insisting on old releases because they don't include some of the new features that make the assignment completely trivial. A lot of my coursework included "do not use the built-in [function_name], write your own." A release that doesn't include said built-in makes it a lot easier on the professor.
These days I seem to be regularly advising people who turn out to be using 2010a or 2011b or 2012a or 2012b or 2013b, sometimes 2008a or sometimes even R13. The requests seem to clump together, with the completely obsolete versions not getting mentioned for a while and then suddenly it is almost as if some university class has required that students use something old.
To be honest, sometimes I wonder if those old version numbers correspond to popular cracks, if that is the reason why more people than one might expect show up using the old versions. And yes, that includes in assignments from professors (that is, I do get the impression some times that some professors are using old cracked versions and that is the reason why they insist that students use something so obsolete.)
As to question 95875, that was fixed in R2014b.
To the others - fair enough; not something I've needed to do yet.
I seem to recall another use as well. Perhaps something along the line of forcing a connection to shut down, as some kinds of resource reservation persist past the program shutting down. For example if you are using ActiveX to talk to a shared server then the server doesn't know that your program has disappeared and that it needs to do (whatever).
Matlab 6.5 crashed, when it was stopped by exit during an audioplayer object is existing. Therefore I added a function in finish.m, which clears all of my functions calling audioplayer. In addition a backup of all modified M-files is triggered.
@Greg — Thank you for reviving this thread. I didn’t know it existed.
For me, it would be ‘automatic array expansion’, introduced (if I remember correctly) in R2016b.
Can’t everyone just learn to use bsxfun? It’s not that difficult!
@Star Strider has it exacly right. In fact, implicit expansion is why I stopped using Matlab in favor of Julia. Matlab is a tool and tools should save me time, but starting in 2017 this fundamentally changed. Implicit expansion, as implemented, was costing me far more time than it ever saved, in similar ways to https://www.mathworks.com/matlabcentral/answers/383533-how-do-i-avoid-getting-fooled-by-implicit-expansion.
Julia just makes implicit expansion pedantic, and it works far better in terms of time spent writing code vs. hunting down accidental dimension mistakes. @Stephen Cobeldick offers some good ideas for how to fix this.
I periodically check back in with Matlab to see if this has been fixed, but alas as @J. Alex Lee points out there is not much active discussion on this point.
so does anyone know why, in the end, it was decided that silently implict syntax for implicit expansion was a better idea than introducing an explicit syntax along the lines of what Stephen said above with different types of binary operators (actually i dont even know what expanding matrix ops means)?
I embraced implicit expansion because for whatever reason I couldn't keep bsxfun syntax straight in my mind, but now I'm being bitten enough by it with inadvertent usage that I've been driven to seek blogs and discussion about this design decision...can't find much since some flurry of activity in 2016 upon introduction and some discussion in 2018...
@Greg: Unfortunately the implicit expansion is sometimes substantially slower than bsxfun.
@Stephen: I agree that these different operators would be useful to avoid bugs. Currently a line of code, which relies on implicit expansion is only clear and clean, if you add a comment, that this is intended.
It would be nice to have four different kinds of binary operator (and transpose):
- strict element-wise
- expanding element-wise
- strict matrix operations
- expanding matrix operations
I came up with a reasonable syntax, but it is not compatible with MATLAB.
Other (recently developed) "scientific" languages that I have used/experimented with seem to be written by programmers for programmers: apparently any thoughts of real mathematics rules being applied was the last thing on their minds.
It's formally called implicit expansion, and it's amazing. Supposedly faster than bsxfun in most cases.
And you are welcome.
I stumbled across this question and thought it would be fun to revive it. A lot has changed, so I wonder how many are still "unmissable," might not be applicable anymore, or any new additions.
Class events. Does anybody actually use these?
The model for these in MATLAB is a little strange. For instance, listeners keep a reference to the object they are listening to, thereby preventing that object being destroyed. The reference is unnecessary given that events are a 'push' mechanism.
This makes the ObjectBeingDestroyed event defined on handle useless, becuase as soon as you listen for it, you prevent the event from ever firing! (Barring evil explicit calls to delete.) It's the ol' watched kettle that never boils.
Class events are awesome. As for listeners keep references, that's precisely the difference between handle.listener and handle.addlistener. You get to choose whether the source holds the reference or the listener holds the reference.
I use them and don't want to be without. However, I cannot say whether the implementation in Matlab is the best.
We do not need deterministic finalisation for reference types, especially when they form part of a reference cycle. More simply put, we don't need MATLAB to go to great lengths to guarantee it will call the delete method on (and free the memory of) objects the very instant that they are no longer used.
The fact that MATLAB has this feature is apparently the cause of performance-sapping overhead. Case in point: it takes O(n) time to get or set a single element in a cell array if that array is a property of a reference-typed object. Try building an O(1) collection class with that restriction!
I'm not aware of any other runtime with managed memory that wastes time giving this guarantee. CPython uses reference-counting similar to MATLAB, but doesn't have deterministic finalisation for objects in a cycle. Java and .NET of course don't have deterministic finalisation for any objects!
The MATLAB language really would be better off though with support for a proper finally block instead.
My pick would be obsolete tools like gatool, which can now be accessed via optimtool.
I think we could do without one curious perversion of functions: a function where you don't pass a variable's value, but you pass the name of the variable instead! I'm lookin' at you, save():
save( 'foo.mat', 'x' );
The code analyzer now correctly picks up on these uses.
myVar = rand(10,1); % no linter warning
save('Test.mat','myVar');
Even the mass name replacements work.
My minify function is not yet updated to deal with this, so I'm still using tools like I described a year and a half ago.
I personally use a separate function to save variables to a mat file. It includes a timestamp and the name of the function that created it. It also makes sure Octave uses the Matlab format, and that Matlab 6.5 can read the files. Using this function I can actually use the tools to change all occurence of the variable names (and the linter doesn't complain anymore). 10 minutes to find inputname and 10 minute to implement the function. 20 minutes of my life that have probably saved me 5 years worth of life span by prevent blood pressure spikes.
I suspect that this is closely related to the origins of MATLAB: back when the height of programming sophistication was a glowing green monitor (80 characters wide) and the use of command syntax for everything. In that context save, load, etc make sense, because command syntax requires that the input must be interpreted as a literal string, and thus can only represent the variable name. Perhaps it was even considered good language design at the time?
Sadly we are now stuck with these strange remnants...
I agree with Walter here, but it is a painful lesson to learn the first 5 times. My problem with save is the Code Analyzer barking that a variable might be unused (or unset in the case of load).
myVar = rand(10,1); % 'myVar' may be unused
save('Test.mat','myVar'); <-- I use it right here Code Analyzer!
People *do* construct (compute) the name of the variable to save, and thus need to be able to pass a variable that contains a string but that variable is not itself the thing to be saved.
I wonder if they're worried about people doing stuff like save('foo.mat',@tan(x))?
They could easily implement a version that accepts variables in the usual manner. I could do it myself using inputname.
I think thats tough. save compares the names given to ones in the workspace, and saves them, I suppose.
I never used the "Start" Button which provides access to tools, demos, shortcuts, and documentation. I would be very curious to know if you are using it !!
I already asked this question on the "Mike on the MATLAB Desktop" blog: MATLAB User Survey (and maybe a free polo shirt) after answering their survey.
Not anymore. =)
There's a "Start" button?
I use it frequently to get to demos for various toolboxes. Sorry to rain on the parade...
I never use that either. Maybe it's designed for people who work on Windows machines, use the tools a lot or aren't old MATLAB users who are set in their ways.
I never use multi-row CHAR arrays.
"there is no obvious mechanism to cellstr() an sprintf() output"
Jan put me on to sprintfc() . Which, oddly, turns out to go across rows instead of down columns.
sprintfc('%d, %d, %d.', [[1;2], [3;4], [5;6]])
ans =
2×1 cell array
{'1, 3, 5.'}
{'2, 4, 6.'}
Yay for string data type! As soon as it is fully functional, I doubt I'll ever use char again.
I use them quite often... mostly for UI related things
I'm using a modified version of DEC2BIN, which assigns UINT8 arrays instead of a CHAR. This uses the half memory and the export to a Mex is more direct.
This is one that I do actually use, and which I think has a lot of internal uses. For example, dec2bin() applied to a vector produces a multi-row char array.
I create formatted output by horzcat'ing together blocks of text. Although that sometimes has relationships to things that could be done through appropriate sprintf(), the char array approach is faster -- and there is no obvious mechanism to cellstr() an sprintf() output (regex split is too much overhead for such a thing.)
I wish the MathWorks would not "dumb things down". This is especially apparent in the GUI development tools, but there are other examples also. Why are the powerful capabilities of the underlying java GUI objects hidden from the user? There is a whole market for utilizing this capability that drives websites like http://www.undocumentedmatlab.com/. People want/need to be able to access this functionality. Thanks to Yair Altman, I have been able to include some of the functionality that I need. But it is so painful (and questionable for future compatibility), the question of whether to use Matlab at all is difficult to justify with my peers.
I suspect that one of the concerns here is the complexity of supporting advanced functionality. I think that sometimes the need to support the basic user overshadows the needs of people who want everything a GUI has to offer. Most unfortunate.
quit
I would never miss that function because matlab is always open on my laptop :)
FYI in the Preferences for MATLAB, the General section has an item for Confirmation Dialogs. One of the dialogs you can enable (it isn't on by default) is "Confirm before exiting MATLAB".
I just got bit a few minutes ago, went to dbquit and accidentally quit instead, accidentally closing my session :(
Really? Cool (in the "I didn't know that" meaning, not the "that's an awesome way for it to behave" meaning).
Clicking the x on the desktop is not the equivalent to quit or exit: any GUI that has been opened on your behalf that uses internal figures (perhaps Java based) can survive being x'd. x'ing the desktop does not reliably close Simulink windows, for example.
Clicking the x in the MATLAB desktop (not the Editor or a running app, etc.) is equivalent to quit or exit.
Point taken for testing framework - I'm still working toward that.
Clicking the x in the corner only gets that one window, not all of the other windows one might have open.
But with respect to wanting to programmatically kill a MATLAB session: Running in an automated mode where you know the session is finished. Especially in a testing framework were you can't be sure of what got created or not.
I agree, quit and exit both seem pointless. Click the x in the corner - why in the world would you ever programmatically want to kill the MATLAB session?
Even when you're installing a new version?
It would be helpful, if a modification of the window icon will not conflicts with the license conditions.
When I open 120 Matlab figures, it can be helpful to group them optically in the popup-menu of the Windows-taskbar, e.g. by different colors in the icon.
Case-insensitive command recognition.
When I'm working on Linux, I have to consider the correct upper/lower case. The ability to call a command with a deviating case is a source of bugs and not a valuable freedom.
I appreciate, that case conflicts create a warning in modern Matlab versions.
@Steven: Thanks. I can't believe it was that long ago (I remember the time when it was a warning).
0 Replies