What is missing from MATLAB #2 - the next decade edition

61 views (last 30 days)
Meta threads have a tendency to grow large. This has happened several times before (the wishlist threads #1 #2 #3 #4 #5, and 'What frustrates you about MATLAB?' #1 and #2).
No wonder that a thread from early 2011 has also kept growing. After just under a decade there are (at time of writing) 119 answers, making the page slow to load and navigate (especially on mobile). So after a friendly nudge; here is a new thread for the things that are missing from Matlab.
Same question: are there things you think should be possible in Matlab, but aren't? What things are possible with software packages similar to Matlab that Matlab would benefit from? (note that you can also submit an enhancement request through support, although I suspect they will be monitoring activity on this thread as well)
What should you post where?
Wishlist threads (#1 #2 #3 #4 #5): bugs and feature requests for Matlab Answers
Frustation threads (#1 #2): frustations about usage and capabilities of Matlab itself
Missing feature threads (#1 #2): features that you whish Matlab would have had
Next Gen threads (#1): features that would break compatibility with previous versions, but would be nice to have
@anyone posting a new thread when the last one gets too large (about 50 answers seems a reasonable limit per thread), please update this list in all last threads. (if you don't have editing privileges, just post a comment asking someone to do the edit)

Answers (39)

cui,xingxing
cui,xingxing on 7 Feb 2021
Edited: cui,xingxing on 8 Feb 2021
Deep Learning toolbox:
How to visualize the changes in dlarray/weight distribution with histograms in deep learning?
Histogram displays how the trend of tensor (weight, bias, gradient, etc.) changes during the training process in the form of histogram. Developers can adjust the model structures accurately by having an in-depth understanding of the effect of each layer.
  6 Comments
cui,xingxing
cui,xingxing on 9 Feb 2021
@Adam Danz Thank you for your suggestions, I look forward to the official future version will be greatly improved!
cui,xingxing
cui,xingxing on 5 Jan 2023
it's lucky to hear that recently matlab version support deepnetwork visualize weight distribution. here is one example link

Sign in to comment.


cui,xingxing
cui,xingxing on 7 Feb 2021
Edited: cui,xingxing on 1 Apr 2021
Deep Learning toolbox:
and so on....
The above are influential applications of deep learning in various aspects, but it is difficult to reproduce in matlab. Although Matlab2019b version supports automatic differentiation mechanism, it is still difficult to implement algorithms in matlab. The efficiency of the differentiation mechanism is not high, and many operators do not support it. I tried to implement the more famous yolov3/v4 algorithm with the latest MATLAB2020a version, but it is still not satisfactory
In summary, my personal suggestions are like my personal answer above, and I hope that future versions can improve a lot!
以上都为深度学习在各个方面有影响力的应用,但是在matlab中复现困难,虽然Matlab2019b版本支持自动微分机制,但仍然不易在matlab实现算法,微分机制效率不高,很多operators也不支持。。。
总之,我的个人建议就像上面的个人回答建议一样,我希望将来的版本可以有所改善!
  1 Comment
cui,xingxing
cui,xingxing on 24 Sep 2021
I have been following the latest development progress of "deeplearning toolbox", and although there are many new features listed, most of them are superficial improvements with very limited substantive support for the "operator", which is still very inadequate for experienced and in-depth researchers.
I hope that mathworks will seriously develop basic modules for the toolbox, instead of small features that are not very important to attract beginners.
我一直在关注“deeplearning toolbox”的最新开发进展,虽然有很多新的功能项被列出来,但这些大部分都是表面上改进,实质上的支持operator非常有限,对于有经验的深入研究者来说还显现的非常不足。

Sign in to comment.


Jim Svensson
Jim Svensson on 24 Oct 2021
Fix the semantics of "clear".
"clear all" does not clear all, but "clear classes" does. Go figure. I want a way to clear classes and only classes.
  1 Comment
Jim Svensson
Jim Svensson on 24 Oct 2021
Clear also cannot clear specific classes in different packages if they have the same name. I.e. pkg1.my_class, and pkg2.my_class. Matlab's package system is broken, but at least some things could be improved.

Sign in to comment.


dpb
dpb on 10 Sep 2020
Editor won't restrict a substituion to selected area...best it knows of is the function. Uncool in the max! I'm now having to fix up a bunch of stuff shouldn't have to have done... :(

Walter Roberson
Walter Roberson on 13 Sep 2020
A "soft interrupt" -- that is, an interrupt that can be handled with try/catch .
For example I am running a long calculation at the moment that iterates several times, and each iteration can take more than an hour. I don't always have the patience to wait through as many iterations as I asked for. For my purposes, the output of the last successful iteration would be "good enough" if I were to ask to interrupt the function.
I can control-C, but that interrupts the function completely, losing all of the outputs, and losing the function variables.
If I could somehow "soft interrupt" and have it return the current values of all variables, then that would be good enough for my current task. But the generalization of that would be the ability to catch a soft interrupt in a try/catch so that the code could make whatever final summariziation it needed to in order to create usable output variables. Furthermore, even though my own routine might be happy to return the "last good" values of the output variables, any soft-interrupt I requested might well get received while some lower-level routine had control that did not know about soft-interrupts, so I would want interrupt (with no return values) to apply to those layers until control reached my handler for a clean run-down.
  7 Comments
Walter Roberson
Walter Roberson on 14 Sep 2020
onCleanup would have to either save() or store into global variables. The point is to be able to have a smooth return of values.
Outputs not assigned would still generate the same error messages as at present.
Function interrupted at unknown state is no worse of a problem than functions that error and are caught by try/catch at present.
It is common for programming systems to have a control-C handler .
Sindar
Sindar on 3 Oct 2020
My solution in a similar case was to check whether a certain file ('FAIL_MODE.txt') exists in the directory at the end of each iteration. If it does, break the loop. Then, to stop the program, all I had to do was create the file (which is pretty trivial unless Matlab has frozen the whole computer)

Sign in to comment.


Michael Foote
Michael Foote on 20 Oct 2021
In the code analyzer, there is no easy way to find what #ok directive controls a particular flagged issue.
(And no overall list of the available #ok directives, at least that I can find. Even the enable/disable messages in preferences don't show them.)
  2 Comments
Rik
Rik on 21 Oct 2021
Maybe I've only looked in the wrong places, but the changes from release to release about what is marked as a warning by mlint are poorly (or not) documented in the release notes.
So there are more things leaving room for improvement regarding this.
Steven Lord
Steven Lord on 22 Sep 2022
Perhaps the codeIssues function introduced in release R2022b will be of use to you. The CheckID variable in the issues table stored in the codeIssues object is the identifier you'd use in the %#ok pragma to suppress Code Analyzer's reporting of that particular issue.

Sign in to comment.


Shae Morgan
Shae Morgan on 31 Jul 2020
facet_wrap or facet_grid (or general ggplot2 functionality) version of subplots, or some altered, simpler customizability for subplotting subsets of data.
gramm is an available toolbox, but it'd be nice to have it built in

Rafael S.T. Vieira
Rafael S.T. Vieira on 31 Jul 2020
Edited: Rafael S.T. Vieira on 31 Jul 2020
I would love to have a command TeX2sym and sym2TeX. With it, we could bring formulas from LaTeX and run them in MATLAB and the other way around. It is a tedious work doing it by hand, and I could bet most MATLAB users do it or will do it eventually.
Another useful feature to add would be arbitrary-precision arithmetic...languages such as python and Java (with Bignum), allows unlimited precision when dealing with integers at least. Granted that It is slow, but I believe that the MATLAB team could do something better. And I honestly feel like MATLAB is missing a feature by not having it...even some competing software has it.
And finally I was considering buying the Text Analytics Toolbox, and it would be nice, if it could have a grammar/spell checker. Even if it is not as advanced or doesn't contain all words. With live scripts, we can write an interactive document, so it would be nice if MATLAB could correct our spelling (even if it required a ToolBox to do it).
  5 Comments
Rafael S.T. Vieira
Rafael S.T. Vieira on 1 Aug 2020
Edited: Rafael S.T. Vieira on 1 Aug 2020
Thank you for your interest, Walter and Rik. I believe that It is best to teach ourselves to code in a particular way, which will allow MATLAB to convert it to sym, than to be doing the task by hand every time.
Operator precedence could take care some of these issues. If \sin x + y was the input, then left-to-right precedence could dictate the output to be sin(x) + y. And to obtain sin(x+y), we would have to code in LaTeX \sin{x+y} or \sin(x+y).
Implied multiplication is indeed very common in mathematics and latex. On the other hand, it is also almost ubiquitous that variables are written just as single letters (especially if we are writing implied multiplication).
Finally, a command like tex2sym does not need to contemplate every math package imho, just some set of commands and macros. MATLAB could even return its best guess, and let us do the remainder of the task. Of course, ideally, we would just copy the contents from environments like $$ and \[ ... \] and paste them into MATLAB for a tex2sym conversion.

Sign in to comment.


Walter Roberson
Walter Roberson on 9 Sep 2020
I know I've said it before, but it's still missing and still important:
We need a way to gather all of the outputs of function call into a cell in the middle of an expression .
I know this may be tricky to implement internally. There are internal rules that are hard to work out, that have to do with how many outputs to request from functions. For example,
[A, B] = cellfun(@C, D, 'uniform', 0)
somehow passes knowledge of "two outputs" to C -- for example if you were to use @max then A would be a cell array of the maxima and B would be a cell array of the indices. The situation can get more complicated than this, and figuring out all the cases can make your head hurt. But we do know that any expression C(D(E)) that D(E) will be evaluated asking for exactly one output and that would be passed into C... but the knowledge of multiple outputs would be passed to C and yet not D.
The number of outputs to use is not inherently clear. If for example you call ode45 and ask to gather the outputs, are you asking for the common TOUT, YOUT case, or the full TOUT,YOUT,TE,YE,IE ? There are some cases where extra outputs can be expensive to calculate, so even though an operation that gathered "maximum" outputs might be useful, it is not always desireable, so ability to select the number would be useful.
Then there are issues with, for example, deal(), where you can have any number of outputs with just a single input:
[A,B,C,D] = deal(123)
would initialize A, B, C, and D all to 123. So if you ask to gather "all" of the outputs from deal(123), that number is not well defined.
Working these things out is not trivial -- but it is a really missing bit of the language.
There might be an opportunity for a syntax such as {}name -- e.g.,
arrayfun(@(X0) {}ode45(@f, tspan, X0), x0s)
meaning to gather all of the outputs of the call. At present, {} is not valid before a name.
  2 Comments
Bruno Luong
Bruno Luong on 9 Sep 2020
Edited: Bruno Luong on 9 Sep 2020
Why nargout doesn't meet what you ask?
function varargout = foo(varargin)
varargout = cell(1,nargout);
[varargout{:}] = deal('dummy');
fprintf('request with %d outputs\n', nargout);
Test
>> [A]=cellfun(@foo, {1 2 3}, 'UniformOutput', false);
request with 1 outputs
request with 1 outputs
request with 1 outputs
>> [A,B]=cellfun(@foo, {1 2 3}, 'UniformOutput', false);
request with 2 outputs
request with 2 outputs
request with 2 outputs
>>
Walter Roberson
Walter Roberson on 10 Sep 2020
Bruno,
Imagine that you want to implement
[temp{1:3}] = ndgrid(-1:.1:1);
C = cell2mat(cellfun(@(M) M(:), temp, 'uniform', 0);
That is, you want a single array in which each of the columns is one of the outputs of ndgrid(). And you want to do it as a single expression.
ndgrid() does not have a fixed number of outputs -- it is not like sin() with one fixed outputs, or max with two fixed outputs. nargout(@ndgrid) is -1 -- in other words the declaration is like
function varargout = ndgrid(varargin)
If you wanted to capture all of the outputs of max() then you could query ndgrid(@max) to get 2:
function outputs = gather_outputs(f, varargin)
n = nargout(f);
[outputs{1:n}] = f(varargin{:});
end
and you could
gather_outputs(@max, rand(3,5))
and this would be fine for gathering the two outputs of max into a single cell array.
But if we try to
gather_outputs(@deal, [])
then nargout(@deal) is -1 and if we said "Okay, take the absolute value of that -1" then we would be doing
[outputs{1:1}] = deal([])
which would give you just {[]} as the output.
This shows that you cannot just look at nargout() of the function you are invoking, such as @max or @deal .
Can we just look at nargout of the overall expression to determine the number of outputs to use for deal? No,
C = cell2mat(cellfun(@(M) M(:), gather_outputs(@ndgrid, -1:.1:1), 'uniform', 0));
would at best tell you that nargout is 1 (the C variable). You need something else to tell you the number of outputs you want to get -- something like
function outputs = gather_n_outputs(f, n, varargin)
[outputs{1:n}] = f(varargin{:});
end
and then you could
C = cell2mat(cellfun(@(M) M(:), gather_n_outputs(@ndgrid, 3, -1:.1:1), 'uniform', 0));
The request is to build this kind of facility in to MATLAB instead of having to write true functions like gather_n_outputs and have to pass function handles into them. Some syntax like
C = cell2mat(cellfun(@(M) M(:), {3}ndgrid(-1:.1:1), 'uniform',0));
where the hypothethical new syntax {3} indicates that you are requesting 3 outputs and that you want them gathered in a cell array. A common alternate syntax would be {} to request all of the outputs, like
C = cellfun(@(V) V.^2, {}max(rand(3,5)), 'uniform', 0)
which would hypothetically gather both (all) outputs of the max() call into a cell array that would then be available for further processing.
If you just used
C = cellfun(@(V) V.^2, max(rand(3,5)), 'uniform', 0)
then the knowledge of the single output would be carried through into the cellfun, which would tell max() to only emit a single output, so you would not get the second output processed. And the first output would be numeric not cell, so you would need arrayfun instead of cellfun...)

Sign in to comment.


Sindar
Sindar on 5 Nov 2020
Ok, this is pretty minor, but:
For common functions that return values as the first output and indices as the second, it would be nice if there was a direct way of getting the indices, so I could do things like this:
x = [1 2 5 4 5];
y = 1:5;
y_xsorted = y(sortInd(x));
% or
y_xunique = y(unique(x,'ia'));
instead of needing to create temporary variables:
x = [1 2 5 4 3];
y = 1:5;
[~,idx] = sort(x);
y_xsorted = y(idx);
[~,idx] = unique(x);
y_xunique = y(idx);
I know I could make wrappers myself, but this seems like a case where a builtin function could potentially be noticeably optimized. (And, is more straightforward than rebuilding the whole output system)

cui,xingxing
cui,xingxing on 7 Feb 2021
Edited: cui,xingxing on 8 Feb 2021
MATLAB
I very much hope that the official version will strengthen the readstruct function in the future! Lack of complete uniformity to support more format requirements.

Walter Roberson
Walter Roberson on 18 Oct 2023
I'm sure I mentiond this at some point... but it would be useful if you could substitute a logical index for more than one dimension.
For example:
img = imread('flamingos.jpg');
intens = rgb2gray(img);
mask = intens > 128;
newimg = img;
At this point, we would like to be able to use something like
%newimg(mask, 3) = 255 - img(mask, 3);
but that is not going to work, and instead we need to proceed something like
temp = img(:,:,3);
temp(mask) = 255 - temp(mask);
newimg(:,:,3) = temp;
subplot(2,1,1); image(img); title('original');
subplot(2,1,2); image(newimg); title('modified')
Now, there is a way to do it without a temporary variable, but it is ugly...
img = imread('flamingos.jpg');
intens = rgb2gray(img);
mask = intens > 128;
newimg2 = img;
newimg2(find(mask) + 2 * numel(mask)) = 255 - img(find(mask) + 2 * numel(mask));
figure;
subplot(2,1,1); image(newimg2); title('modified -- indexing')
isequal(newimg, newimg2)
ans = logical
1

Seth Wagenman
Seth Wagenman on 31 Aug 2020
Ability to convert Python items to MATLAB data types (other than numpy arrays) inside of MATLAB, rather than inside of Python using the admin-rights-required API: https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html?s_tid=srchtitle
  2 Comments
Steven Lord
Steven Lord on 10 Mar 2022
I'm not 100% sure if you had specific types in mind when you said "Python items" but as of release R2022a you can convert Python list and tuple types to MATLAB types.
Steven Lord
Steven Lord on 22 Sep 2022
There's an entry in the Release Notes for release R2022b that discusses converting scalar logical and numeric Python types to MATLAB types.

Sign in to comment.


Tim
Tim on 5 Nov 2020
The following changes to the internal volume renderer would make Matlab much more useful for volume visualization:
  • True RGB volume visualization (vs. just scalar data + colormap)
  • Independent, decoupled specification of alpha values and intensity values
  • The ability to combine volume images with standard axes and axes objects like points, lines, patches, etc.
  1 Comment
Walter Roberson
Walter Roberson on 24 Aug 2022
And add the ability to pass axes scales, similar to the image() XData property, and maybe even support irregularly spaced points

Sign in to comment.


Mario Malic
Mario Malic on 13 Nov 2020
When typing code, if user wants to reference a variable or a function, one could click tab and get a matching list of functions and variables. Would it be useful to split this functionality with modifier if user wants to reference one of the two? As an example Shift +Tab for variables and Tab for functions and variables (not to break the current functionality).

Bruno Luong
Bruno Luong on 17 Nov 2020
Edited: Bruno Luong on 17 Nov 2020
No big deal but I wish SIGN(X) function could return 1 for X=0 instead of 0. May be implementing an option to not break the compatibility.
I just rarely use SIGN because of this exception choice.
  19 Comments
Stephen23
Stephen23 on 18 Nov 2021
Edited: Stephen23 on 18 Nov 2021
"Perhaps I’m missing something, however if 0 can never be either positive or negative"
You might be missing the fact that IEEE 754 has signed zeros. Signed zeros explain why this happens:
x = -0;
1/x
ans = -Inf
Bruno Luong and I would like a function that gives the sign of that zero before we do a calculation with it.
Sometimes I work with zeros and infinities as values, so this is actually information that I have needed to use. Currently I have to perform an operation on the value to determine the sign, or do some bit-bashing and scale the results of that (much as Bruno Luong showed). The goal is that sign.
Star Strider
Star Strider on 18 Nov 2021
I’m not up on IEEE 754 standards obviously, so signed zeros are new.

Sign in to comment.


Camilo Andres Manrique Escobar
One thing would be: defining classes in notebooks (Live Scripts in MATLAB case). That's a normal thing for years now in Python, for example.

Jim Svensson
Jim Svensson on 24 Oct 2021
Maintain dimensions when getting a field of a class.
If Data is a 3x2x4 array of objects/structs with a field "foo", then Data.foo should be an 3x2x4 array of the type of "foo". Not a 1x24 array, or is it the other way around.
  3 Comments
Rik
Rik on 24 Oct 2021
It currently is neither: it's a comma separated list.
for i1=1:3,for i2=1:2,for i3=1:4,s(i1,i2,i3).Data=rand;end,end,end
s.Data
ans = 0.9787
ans = 0.5449
ans = 0.2691
ans = 0.9030
ans = 0.7619
ans = 0.5311
ans = 0.8777
ans = 0.5484
ans = 0.2540
ans = 0.7540
ans = 0.6646
ans = 0.9153
ans = 0.6058
ans = 0.2581
ans = 0.6459
ans = 0.4237
ans = 0.1189
ans = 0.1992
ans = 0.3687
ans = 0.4382
ans = 0.7179
ans = 0.2574
ans = 0.5783
ans = 0.1151
To do something with it you'll have to capture it with [] or {} or a function that allows arbitrary input.
Jim Svensson
Jim Svensson on 24 Oct 2021
Yes you are right, now I remember. Always have to do something like "foo = [Data.foo]".

Sign in to comment.


gwoo
gwoo on 26 Oct 2021
Being able to access the properties/methods/fields of an object/struct even after indexing into one would be a big deal.
Currently, if you have a struct A, with fields size and count, you could do A. then tab to show the options for the fields. But if you do A(1). you cannot now tab to show the options for the fields. Same with an object. So the discoverability is gone.
I want to be able to index into an object/struct and still have the available fields/properties/methods for that parent show up.
  2 Comments
Mario Malic
Mario Malic on 27 Oct 2021
+1 on this: Currently, if you have a struct A, with fields size and count, you could do A. then tab to show the options for the fields. But if you do A(1). you cannot now tab to show the options for the fields. Same with an object. So the discoverability is gone.
Paul
Paul on 27 Oct 2021
I just tried this on 2020b and hitting tab after A(1). showed the fields.

Sign in to comment.


Bruno Luong
Bruno Luong on 27 Oct 2021
Edited: Bruno Luong on 27 Oct 2021
Probably it breaks compatibility, but it would make functions/operators svd, *, ', .' dealing with n-d arrays similar to pagesvd, pagemtimes, ... followed by appropriated reshape.
Extend the pagexxx with matrix left/right division, lu, qr, chol, eig, etc...
  12 Comments
Adam
Adam on 9 Feb 2023
Ah, that's the thing I was missing, thanks for clarifying that
Bruno Luong
Bruno Luong on 9 Feb 2023
Edited: Adam Danz on 9 Feb 2023
@Adam Not only the floating point rounding can create different numerically result, but what matters even more is that the floating point counts when multiply matrices can be different.
Consider the product
A*B*x
with
  • A: p x m,
  • B: m x n,
  • x: m x 1
with p = 100, n = 100, m = 1000,
It is much cheaper to perform
A*(B*x) than (A*B)*x.
And in general the less operations is carried out, the less round-off has effect on the final result.

Sign in to comment.


dpb
dpb on 27 Nov 2022
read/writetable from/to Excel workbooks should be able to return/write the comment (now called something else, I forget what) field and the formula associated with the cell as well as the value. While one can write COM to do so, it then takes either using COM entirely (can be a lot of work) or have to use both high-level and COM on the same file; either of which options isn't ideal. Sure, one could forego Excel entirely since have MATLAB, but unfortunately can't always have what we want in that regards.
One can mung on the old xlsread/write routine and add stuff into it, but it's also kinda' klunky and while more convenient in some ways as compared to writing all COM totally from scratch isn't nearly as convenient as would be a higher-level interface with the other current toolset.
There's a hook to a function call in xlsread although I was never able to get it to work to do either of the above; because the Excel COM object isn't exposed to the function to be able to make direct access from that function.

dpb
dpb on 1 Jan 2023
Maybe there's a way I've not found, but I wish arrayfun and cellfun would have automagic argument expansion so one could pass other arguments to the anonymous function without having to replicate them manually to match the others. This would add greatly to the convenience in using either; the present working example happens to be building a set of target range expressions to stuff into a cell array that will be written to Excel although that really has nothing to do with the request/enhancement, just happens to be current time was frustrated that there's no way to pass constants to the anonymous functions to allow them to be generalized.
Example:
Building a variably-sized workbook where it is desirable that the sums over a section of the sheet be formulas rather than the current fixed constant value of the data as the sheet will subsequently be modified by hand; the tool is to build the original working pattern by compending various data sources and arranging for the end user...
It boils down to the point at which one has a set of row range indices and a set of columns over which to build the formula and insert into the cell array which is subsequently written to the workbook. That code looks something like
% anonymous function that builds Excel =SUM(r1:r2) expression for given row range, column
xlsSumRange=@(r1,r2,c)strcat('=SUM(',xlsAddr(r1,c),':',xlsAddr(r2,c),')');
% typical use
col=xlsCol2Col('G'); % another internal translation layer of local array position from Excel column
cOut(isTotal,col)=arrayfun(@(r1,r2,c)xlsSumRange(r1,r2,c),RS1,RS2,repmat('G',numel(RS)-1,1),'UniformOutput',0);
col=xlsCol2Col('K'); % another internal translation layer of local array position from Excel column
cOut(isTotal,col)=arrayfun(@(r1,r2,c)xlsSumRange(r1,r2,c),RS1,RS2,repmat('K',numel(RS)-1,1),'UniformOutput',0);
This works, but the expression "repmat('G',numel(RS)-1,1)" needed is really inconvenient and clutters up the code legibility greatly. I've had any number of similar case in the past where an anonymous function is useful shorthand but then to use more than once requires a workaround like the above.
The alternative is to redefine the anonymous function dynamically and embed the constant inside it for the given invocation.
To visualize, an example output for the above for one invocation looks like for the call with column 'G'
K>> arrayfun(@(r1,r2,c)xlsSumRange(r1,r2,c),RS1,RS2,repmat('K',numel(RS)-1,1),'UniformOutput',0);
ans =
3×1 cell array
{'=SUM($G$3:$G$17)' }
{'=SUM($G$22:$G$372)' }
{'=SUM($G$377:$G$414)'}
K>>
The above could be in a loop over the number of columns instead of using the explicit columns, but was part of still rearranging the output file structure at the time...and, haven't taken the time to clean it all up yet...
  8 Comments
dpb
dpb on 2 Jan 2023
Thanks @Stephen23, @Bruno Luong and @Steven Lord for the feedback and example coding...I'll snag the code snippets and stuff away with the present code in a comment block and come back and revisit when some of the time pressure lessens...
Andrew Janke
Andrew Janke on 4 Jan 2023
+1 on this, @dpb. This "implicit scalar expansion for (array|cell)fun args" is a use case I've had occasional cause to want, and haven't been able to figure out a good way to do, except for ditching arrayfun and Functional Programming style and inverting the logic/control-flow to just write a vectorized or "regular Matlab" version of the function I'm trying to do.
In other use cases, as long as I don't care about method-call overhead, I've been able to wrap the value to be expanded in an "infinite copies" array, like this SPAM thing here:
classdef SPAM
% "spam" a value to every element of an infinite virtual array
properties
Value
end
methods
function this = SPAM(x)
this.Value = x;
end
function out = subsref(this, S) %#ok<INUSD>
out = this.Value;
end
end
end
But that doesn't seem to work with cellfun/arrayfun, because it looks like they do an explicit "size(...)" test on their inputs before trying to index in to them.
>> x = magic(3);
>> z = arrayfun(@plus, x, SPAM(420))
Error using arrayfun
All of the input arguments must be of the same size and shape.
Previous inputs had size 3 in dimension 1. Input #3 has size 1
>> spam = SPAM(420);
>> z = NaN(size(x)); for i = 1:numel(z); z(i) = x(i) + spam(i); end
>> z
z =
428 421 426
423 425 427
424 429 422
>>
Can't say I blame Matlab for this, though. I like explicit size-conformity checks; catches bugs more often than it prevents features.

Sign in to comment.


dpb
dpb on 8 Feb 2023
Edited: dpb on 8 Feb 2023
I wish clearvars had an optional "do-nothing" flag a la the /L switch in CMD XCOPY to display the variable that would be cleared with the given variables list...would let one confirm a wildcard expression didn't accidentally wipe out something wished to have kept; particular with the -except clause.
  1 Comment
Andrew Janke
Andrew Janke on 8 Feb 2023
Oooh, good idea. PowerShell does this for a bunch of their cmdlets like xcopy. I call this a "dry-run" or "what-if" run. I think PowerShell and recent Windows have standardized on the -WhatIf option for this.

Sign in to comment.


Adam
Adam on 16 Feb 2023
Edited: Adam on 16 Feb 2023
When defining Abstract methods on a class, I would like to be able to fix the arguments on the abstract class.
Something like this would be usefull:
classdef AbstractSuperClass
methods (Abstract)
function AbstractMethod(self,input1,input2)
arguments
self
input1 (1,1) double
input2 (1,1) double
end
% no function body because it is abstract
end
end
end
Right now, I always end writing two versions of the same method to avoid the need to copy the arguments validation block to the subclass:
classdef AbstractSuperClass
methods
function Method(self,input1,input2)
arguments
self
input1 (1,1) double
input2 (1,1) double
end
abstract_version_of_method(self,input1,input2)
end
end
methods (Abstract,access=protected)
abstract_version_of_method(self,input1,input2)
end
end
but this feels wrong to do it and results in programming errors because I forget what the input signature of the method is, the above syntax would be more elegant and would allow for checking whether the input signature of the implementation of the method follows the definition in the abstract class.
With the new arguments (output), I would even be able to fix the output type of my abstract function
  1 Comment
Andrew Janke
Andrew Janke on 17 Feb 2023
Oooh, tentative +1 on this. This is something I hadn't even thought of, and I'm not sure what all the implications of doing this in Matlab would be. But it's basically how traditional static OOP languages like Java and C++ work, and there it's obviously the right thing and we just take it for granted. There, the types etc of the input arguments are part of the interface or signature of those methods, and subclasses must conform to them, and that just makes things easy to reason about. (IMHO.)

Sign in to comment.


dim-ask
dim-ask on 28 Aug 2023
An AI copilot feature-option in the IDE, where either matlab has their own model (optimal) with adjustable privacy that users can determine (to avoid possible gdpr etc issues), and/or the capacity to configure the copilot to work with an LLM service of our choice (also possibly run locally).
In the current state of afairs, continuing using an ide with no copilot integration is non-sustainable. Not for the future, for like yesterday. I already feel quite anxious falling behind compared to python users in terms of copilot language-specific support. There is a ton of python stuff out there that LLMs are trained on, and ime existing LLMs are worse in many other languages, including matlab. The direction copilots seem to get is different "specialised experts", and it seems finetuning different models to specific languages each has potential.
It would be great if Mathworks finetuned an LLM, which could, for example, either be some version of GPT3.5/4 that we could then use through an API, or a version of codellama that is (almost) open source that then mathworks itself could provide through an API (as an extra toolbox, or subscription, or whatnot). Or both options (why bet on one horse only?) or something else entirely. Also, it would be great if people who write matlab using other environments like neovim or vs-code had access to that model too. Even better if it is available for people to also run locally, like the codellama derivatives.
Finetuning a model should not be a great deal for a big company like mathworks, people with much less budget do this sort of thing nowadays. Mathworks has access to tons of matlab code they could use, and I cannot see anything putting any great obstacle to that apart from intention. There are a lot of companies and startups right now doing this sort of thing for other languages. But if mathworks does not do that with matlab, I don't know if anybody else will bother with it. So please consider offering something in that direction, because very soon it seems that writing code without option for copilot assistance will not be conceivable.
  2 Comments
Walter Roberson
Walter Roberson on 28 Aug 2023
I wonder if I will get any residuals for the various models that train on the numerous answers I have given? Somehow I suspect not...
dim-ask
dim-ask on 29 Aug 2023
In some sense, you already deserved so even before.

Sign in to comment.


Mikhail
Mikhail on 2 Aug 2020
Some (well, most) dynamic programming languages allow for an experienced developer to have an insight look into how their code is actually executed by the runtime environment.
They are able to see the parse tree and the compiled byte code.
They are able to see what parts of code are JIT-compiled, and how exactly the are compiled. When something is not compiled, they are able to see why.
The developer doesn't have to guess whether a particular optimization has kicked in or not. They know for sure how each and every object in their code is handled (whether it is CoW, passed by reference, passed by value).
I'd love to see these capabilities in MATLAB, too.
  8 Comments
Mikhail
Mikhail on 2 Aug 2020
> I tell people to use readfile(filename_or_url) and use that result, instead of telling them how to figure out if a file is UTF8 or ANSI and which exact conversion that requires for their specific OS and version of Matlab/Octave.
> ...
> The function is not suddenly horrible because you can't have a peek at the implementation and optimize your workflow accordingly. Why would the language as a whole be any different?
Given that I can't peek at the function's implementation, this function suddenly becomes horrible when I have a file double encoded to UTF-8 (and so your function returns garbage) and you considered your users too dumb to allow them to mend this function for their needs.
Same goes for the language.
Rik
Rik on 2 Aug 2020
That doesn't make the function horrible, it just means the function is not suited to your needs. I don't complain that my hypothetical electric stove can't cool things down, even though with a TEC it is possible to both heat and cool down things with a single electrically powered device.
Although you could re-use a lot of the internals of readfile to fix double UTF-8 encoded files, the problem is not the function, it's the double encoding. Fixing double encoding is a different task from reading a file correctly. It wouldn't be a matter of 'mending my function', it would be re-using internal functions for a different goal. The word 'mending' implies my function is broken, but returning a double encoded file in a corrected form is not living up to the contract that the name of the function is offering.
Also, there are more reasons to close down the source than just thinking your users are dumb (suggesting otherwise sounds a lot like assuming bad faith). As an example: if you want to provide a function for a license fee, it would be plain stupid to have your license check in an m-file, since it would be almost trivial to circumvent.

Sign in to comment.


dpb
dpb on 6 Sep 2020
Edited: dpb on 6 Sep 2020
A ready-built insertion method for tables, arrays, etc., so don't have to do all the under-the-hood indexing manually...given an array of the right size and matching index, if had table (say), then
tMyTable=insert(tMyTable,indices,tNewData);
ideally, an option with keyword 'Empty', T|F would be available as well.
Maybe I'm missing some magic pixie dust, but I've been unable to figure out a way to this without physically moving a section at a time to insert the new row which means working from rear to front to avoid changing the indices to the insertion points or by catenating the pieces starting from the front.
  7 Comments