MATLAB Answers

Paulo Silva

What is missing from MATLAB?

Asked by Paulo Silva
on 14 Feb 2011
Latest activity Commented on by Walter Roberson
on 1 Jul 2015 at 8:00

I'm curious, is there something you wish to do with MATLAB but you can't, maybe something you can do with other similar software but can't with MATLAB?

  4 Comments

Walter Roberson
on 14 Oct 2011

But can you do that in other similar software, Nitin?

Andrew P
on 26 Feb 2014

Yes, 6 terminal induction machines are possible in other software. PSCAD has a 6 terminal induction machine model, although I don't think it's part of their standard library.

Walter Roberson
on 26 Feb 2014

Huh, PSCAD turns out to be made by an organization on the first north-south road over from here. :-)

Products

No products are associated with this question.

87 Answers

Answer by Walter Roberson
on 14 Feb 2011
 Accepted answer

The result of every expression should be further indexable by all of the index methods. This includes not only function calls but literals or expressions: e.g.,

(1:3:20)(K:K+1)

or

[struct('hello',A+5),B].hello

  9 Comments

Irl
on 19 Mar 2012

A nice way to implement this without a very dangerous extension of existing syntax would be a function that simply indexes into an array, kind of like getfield: my wished-for function, call it getelement, would do this:
getelement([1 2 3;4 5 6],[2 3])
returns 6, i.e., operates like
[1 2 3;4 5 6](2,3)

Raphael Cautain
on 16 May 2012

Several old languages - not solely functional languages - have already this functionality : C, IDL ... The present situation is just a restriction, since the result is safely available in the interpreter. This extension would save memory.

@Irl : while waiting for this :
function output = getelement(expr, subs)
q = num2cell(subs);
output = expr(q{:});
end

Walter Roberson
on 8 Jul 2012

Raphael, the extension would not actually save any memory, except for an entry in the name table. Everything else about the expression would be shared, due to the way "copy on write" works in MATLAB.

T = expression(); T(2,3)

does not take any more memory than expression()(2,3) would. T would be created as essentially a pointer to the memory that describes the type and array dimensions of the expression and the location of the memory block, so doing the assignment only takes enough memory for the name "T" and the pointer.


Jan Simon
Answer by Jan Simon
on 14 Feb 2011

A long term supported version!

The current policy to fix bugs mainly by shipping a new release has the important drawback, that a new relase includes new bugs ever. If reliability is extremely important, e.g. for the prediction of the outcome of surgical operations for children, MATLAB is a fairly good choice, as long as a program runs only on the release it was developped on. I must be able to reproduce the results of a published medical study for 10 years. If such a study needs 5 years to measure the long term effects of a medical treatment, it is really unclear, if I can run MATLAB 2010b in the year 2025. Therefore MATLAB is actually not suitable for a long term study -- but there is a good argument to use it in spite of these facts: The alternatives are even worse.

  5 Comments

Robert Cumming
on 15 Feb 2011

I agree with this point, while compiling (or pcode) can "freeze/lockdown" code - what happens if you have to do some investigations into the internals of your code?
I work in the Aerospace industry and projects are expected to have lifecycle of 10's of years (think Boeing 747 entered service in the 60's and is still selling today). In certification, any data which is analysed/processed using any code must be re-produceable at any point in the the future - bugs and all!! ;)
So we have to keep a log of which version of Matlab was used and must be able to go back to that version if and when required.

Horia
on 3 Aug 2011

Unfortunately, you have to accept the drawbacks of new releases:
Eg:I never arrived to use Photoshop CS4 Extended from within Matlab R2009b, and R2010B, all 64 bits;and I lost a lot of time trying to apply the solutions given by Mathworks, Adobe and forums. Everything works like a charm with 2011a,Photoshop CS5 Extended and the Intel C++ compiler (all, 64 bits).

I'm sure all this is commercial strategy.To use Robert Cumming's example:what would become the car industry if it worked like Boeing?

Jan Simon
on 26 Apr 2012

There is a new service pack for 2010b, although it is 2012 now. I do not have 2010b, such that I cannot download the SP2 and check the improvements. But I'm positively impressed by this special support activity!
I think it is worth to announce this update in public, because it increases the user's trust in the reliability of Matlab substantially.


Answer by Matt Fig
on 14 Feb 2011

Real pass by reference.

  4 Comments

Peter O'Connor
on 15 Feb 2011

should just have an option to create matrices that act as if they were subclasses of handle (pointers).
ie a=rand(1,1000000); b=a; a(1)=2; takes a long time, a(1)~=b(1)
a=*rand(1,1000000); b=a; a(1)=2; would be fast, a(1)==b(1). this'd be practical if calling functions to modify, not copy, a large matrix.

Malcolm Lidierth
on 27 Apr 2011

Peter
How about this?

classdef databucket < handle

properties (Access='public')
Bucket
end

methods

function obj=databucket(data)
obj.Bucket=data;
return
end

function varargout=subsref(obj, varargin)
varargout{1:nargout}=subsref(obj.Bucket, varargin{:});
return
end

function varargout=subsasgn(obj, varargin)
varargout{1:nargout}=subsasgn(obj.Bucket, varargin{:});
return
end

end

end

I've created a set classes that do something like this using data on file, either memory mapped or accessed using low-level i/o so the "Bucket" can be many Gb without having them in memory all at once. With extra work to overload size, double etc and make X(:) a special case, these "nakhur" classes can be used anywhere a double precision array can be used in m-code.

owr
on 21 Jul 2011

Malcolm, databucket is nice but an issue is that subsref in objects is much slower than in native arrays. Try this:

% Start Code
N = 100000;

d1 = randn(N,1);
d2 = randn(N,1);

db1 = databucket(d1);
db2 = databucket(d2);

dres = zeros(N,1);
dbres = zeros(N,1);

tic;
for i=1:N
dres(i) = d1(i).*d2(i);
end
nativetime = toc

tic;
for i=1:N
dbres(i) = db1(i).*db2(i);
end
objecttime = toc
% End code

In terms of the original question though, Ive managed fine without explicit pass by reference. But I can understand why one would want it.


Answer by Aurelien Queffurust on 18 Feb 2011

What is missing in MATLAB?

Here are my two quick thoughts for today :

1) More choice in default uicontrols:

Currently , user interface controls include push buttons, toggle buttons, sliders, radio buttons, edit text controls, static text controls, pop-up menus, check boxes, and list boxes.

I would like to have more custom pushbuttons . I would like to be able to modify the borderwidth (like for uipanel) , to choose another form than rectangle or square like circle , triangle ... I really feel frustrated not to be able to build a GUI with such components . Currently the only thing I do to enhance the design of my softwares is to use CData to add icons ! I always try to find the best backgroundcolor for my GUI ...changing colors is possible but not the form/appearance of the uicontrols.

Except uitable which is quite new, I didn't find any major improvement to build GUI since many years.

2) Documentation in another language

What about a French doc ?!! Translating the doc in Japanese was possible , so doing the same thing in French should be also possible .

Aurélien

My Blog for MATLAB geeks

  0 Comments


Answer by Doug Hull
on 14 Feb 2011

The most effective way to put in an enhancement request for MATLAB is shown here.

It is fine to discuss things, but this forum is not guaranteed to be seen by the right people. The above link is.

  3 Comments

Jan Simon
on 14 Feb 2011

I suggest: Discuss at first here, forward the results afterwards.

Michelle Hirsch
on 17 Feb 2011

I'm certainly watching the discussion! Jan's idea is a good one. You may want to mention if a particular suggestion happened to get lots of votes.

Thanks to all of you for your input.

Julian
on 21 Apr 2011

Doug, may I ask how does one view/navigate/search the enhancement requests submitted this way? Mathworks.com search allows you to search Bug Reports (for example), but I could not see "enhancement requests". Thanks.


Answer by Walter Roberson
on 14 Feb 2011

Graphic support for arbitrary unicode characters.

  1 Comment

Ian
on 15 Mar 2011

yes please! surely matlab should be unicode friendly by now!


Answer by Walter Roberson
on 16 Feb 2011

Exposed documented serialization routines. Currently, to transmit Matlab variables to a different process, about the best method available is to save() to file, send the binary file, read the binary and write it to disk, and load() the variables.

Better methods must exist already for use with parallel processing, so it would help to expose and document them.

  3 Comments

Joan Puig
on 28 Feb 2011

I would love to see this implemented

Ian
on 15 Mar 2011

I would really love to see this too, even if all we have access to is the byte stream result of save we could route somewhere else. Ideally there would be a defined intermediate format.

Mike
on 14 Sep 2011

Yes, Something like this is needed.


Answer by Oleg Komarov
on 17 Feb 2011

Anti-aliasing... MYAA

  1 Comment

Michael Johnston on 3 Aug 2011

Yeah, it's kind of ridiculous that we need to go to the File Exchange to be able to produce reasonable looking figures. The figure export options in MATLAB are pretty weak because they're not WYSWIG... lots of trial and error and visits to File Exchange required to produce something that looks decent in a PDF.


Jan Simon
Answer by Jan Simon
on 14 Feb 2011

It would be very helpful, if the Mex-interface is completely documented. Especially the inplace write access to variables passed by reference is a holy secret - although it is possible already and would be much more efficient.

  1 Comment


Answer by Walter Roberson
on 14 Feb 2011

Programmatic layout routines. I had to create my own, one pass to shrink-wrap a control to the size it needs to hold the value(s), and the second pass to position the control relative to another control.

Exporting from GUIDE produces completely unmaintainable coordinates. It is not an option for producing maintainable software.

  0 Comments


Answer by Daniel
on 5 Apr 2012

A function to check if a string clashes with an official MATLAB function. Something like Jan's UniqueFuncNames, but with support for all MATLAB toolboxes. Preferably something that can handle different MATLAB versions and input classes. In other words randi exists in 2012a, but was it a function in r2008a or is there an fft function for class int16. The "which" function is helpful for your current version, but only for toolboxes you own.

  2 Comments

Jan Simon
on 5 Apr 2012

It would be easy to expand UniqueFuncNames, if somebody with access to full Matlab installations assists.

Daniel
on 6 Apr 2012

While it would be easy, this is something that I think TMW should supply and maintain. I would think they could even automate the process.


Answer by Walter Roberson
on 14 Feb 2011

A notation to be able to represent multi-dimensional data, instead of having to cat(N,...) the dimensions together.

This notation should in turn be understood by (e.g.) load routines

  0 Comments


Answer by Walter Roberson
on 14 Feb 2011

An equivalent to the ?: operator, in which the unselected part does not get evaluated.

  2 Comments

Jan Rubak
on 14 Feb 2011

I've wished for the same, especially for use in anonymous functions.

David Goldsmith on 16 Mar 2011

"I've wished for the same" many times...


Answer by Peter O'Connor
on 15 Feb 2011

ability to enter default inputs like in python as in function out=foo(bar,bar1='arr',bar2='yarr') ...

  4 Comments

Walter Roberson
on 17 Feb 2011

foo(bar) would be treated as foo(bar,'arr','yarr')

foo(bar,bar1) would be treated as foo(bar,bar1,'yarr')

foo(bar,bar1,bar2) would have no default applied.

Walter Roberson
on 7 Jun 2011

The best tool along these lines that I have ever seen was for DEC VAX VMS. The tool allowed one to construct conditional trees of argument processing, so that some arguments would only be expected (or given default value if missing) if other arguments were present, or so that it was possible to say that arguments were incompatible. The default values could vary depending upon which switches were used, I seem to recall. Arguments could be defined as keyword or as positional or as "positional unless given as a keyword". I no longer recall if explicit data types could be given for how the argument was to be stored, but it was possible to restrict the form of input arguments (e.g., to specify that an argument _had_ to be an integer with exponential format disallowed.) Valid values for arguments could be given as a list of specific words. Abbreviations were handled -- only as much of the word as was necessary to disambiguate it was required to be entered by the user.

I miss some features of VMS...

Ben Petschel
on 8 Jun 2011

A nice feature of the R language is non-constant default inputs, for example function(x,n=length(x)), whereas Python defines the defaults at compile time. Having this feature as well as named arguments in the function call such as foo(n=1) would save the tedium of processing varargin.


Answer by Walter Roberson
on 16 Feb 2011

More flexibility to work with I/O streams rather than having to have everything in memory.

As a simple example: unzip a single file starting from the current position in an I/O stream, rather than having to unzip to disk and read the resulting file.

  1 Comment

Walter Roberson
on 17 Feb 2011

I think it would be acceptable for this purpose to introduce a new IOStream object, with IOStream(fid) pulling out the object for the file id #fid . To start the basic properties of the IOStream would be the fields you get from applying fopen() to that fid.

A Position property when read could substitute for ftell(fid), and when set could substitute for fseek(fid,POS,'bof') .

Mainly, though, by having a distinct object class wrapping the fid, it would become easier to overload methods, especially in places where a file name string is expected as the first parameter.

imwrite(Array,IOStream(4)) would write to the given stream rather than to a file name.

This becomes more powerful when you allow IOStreams to become associated with blocks of memory, as per traditional unix memmap semantics -- which allow dual access through the fid and through memory

Or perhaps it would be better to have an IOObject class with subclasses for "stream" (non-seekable) and "block" (seekable) objects. That leads into possibilities such as asynch reads with callbacks, and scatter-gather I/O... maybe even DMA to devices...


Answer by Walter Roberson
on 16 Feb 2011

Pipes / popen() / ability to communicate interactively with other programs without having to use tcp/udp .

  0 Comments


Answer by Walter Roberson
on 18 Feb 2011

Inspired by Carl's csvread requests:

A textscan format specifier indicating that a date was expected at that position, possibly including embedded blanks. A modifier would allow specification of one of the standard date format numbers. Output would be a serial date number.

Extra points for a format specifier that allowed the standard date elements, such as

%t{mmm yy, HH:MM}

  0 Comments


Answer by David Goldsmith on 16 Mar 2011

Multiple inspector instances in one instance of MATLAB: I want to be able to "inspect" more than one object at a time (e.g., to be able to compare property values); presently, I have to launch a new instance of MATLAB for each distinct inspector instance I want to use simultaneously--a tremendous waste of resources! (Don't worry, I'm submitting a formal enhancement request.)

  7 Comments

Image Analyst
on 26 Aug 2013

Yes, that's it! I think it's a major omission that this function doesn't come up when you search for "color" in the help, and it's not even listed as a "see also" in the ColorSpec page of the help. I'll send in a feature request for that. Thanks for telling us about this function.

Jan Simon
on 28 Aug 2013

@IA: It is easy to find:

docsearch color

Then it is about the 600th(!) element in the list on the left, when you sort the results alphabetically, what has been possible in the help browser of R2009a. In R2011b I do not find uisetcolor through docsearch at all. And after too many negative opinions I'm not eager to search in the help browser of R2013a.

So you are right: This will be an important enhancement request. I post a question here also, because it will be published earlier than the modified help text most likely ;-)

Walter Roberson
on 28 Aug 2013

R2013, if I type uisetcolor into the GUI search engine, it shows up without difficulty. But if you tried to search for it without knowing the right verb (e.g., if you were looking for "pick color") then good luck.


Answer by Ben Petschel
on 8 Jun 2011

1. Distinguishing variable from function names in M-Lint. To get around the current limitation, "declare" which names are variables and which are functions, e.g. with %#fdef and %#vdef statements somewhere after the help header. These could be generated automatically e.g. via a dialogue box that asks the user to tick the boxes as to which ambiguous names are which. It would be useful for detecting uninitialized variables and other common typos.

2. Allow pausing/monitoring/debugging calculations mid-flow, e.g. with a pause button, or breakpoints that can be added during program execution, or a variable monitor window that displays variable values in a given workspace while the function/script is running. Would be very useful for monitoring long calculations without killing them.

3. multiple-line anonymous functions, or allow function declarations in scripts.

4. function calls with named arguments and default values in the function definition, e.g. "function f(x=[],n=length(x))" and "f(n=1)".

  2 Comments

Walter Roberson
on 21 Jul 2011

Pausing state for examination without ruining the calculation would be beneficial!

K E
on 13 Jul 2012

Yes, I have always wanted that myself.


Answer by Dan K
on 27 Jan 2012

A true polar plot. I've been using an old copy of mmpolar (thanks Duane) for years. It seems ridiculous that the built in functionality has hard coded axis labels,etc. It's even brutal trying to adjust things that can be accessed, since the underlying coordinates are all Cartesian.

  1 Comment

Walter Roberson
on 28 Jan 2012

Also, we get a surprising number of requests for log-polar plots. Yes, that causes problems for rho that are negative, and requires an infinite amount of canvas to represent from rho = 0 to any positive rho, but people want it anyhow.


Answer by Sean de Wolski
on 14 Feb 2011

Mathcad-like sheets, where things can be easily displayed for the purpose of someone checking your calculations.

  2 Comments

Royi Avital
on 6 Oct 2011

This would be great. Moreover it will be better way to document a code.

K E
on 12 Jan 2012

And you could insert figures/links/cartoons


Answer by Walter Roberson
on 14 Feb 2011

Explicit render to a buffer (array). There are some things that this makes much easier!

  3 Comments

Andrew Newell
on 14 Feb 2011

@Walter, can you expand on this a bit?

Walter Roberson
on 14 Feb 2011

Think of getframe() or saveas()'s ability to save an interactive image to memory or a file. Now skip the getframe() or savas() step by allowing the user to say, e.g.,

renderer buffer VARIABLENAME

and have the pixel results written directly to the variable. You'd possibly need a dots-per-inch kind of parameter in order to determine the drawing density and the virtual screen size, and an option to only capture between certain coordinates would be nice.

For example, the other day someone asked a question in cssm: they had constructed a shaded patch and wanted to capture the pixels along the surface of it for use in further processing. Not an easy task with the current rendering, especially if you want higher resolution than is available on your screen.

Oh yeah, and this render-to-buffer option should be available in batch mode!

Walter Roberson
on 15 Feb 2011

Rendering to a 3D array would naturally result in RGB. Rendering to a 4D array might usefully include alpha information in some cases. I imagine that in some cases people might want to render to CMYK or YCrCb; at the moment there are a few routines that can translate RGB to CMYK or YCrCb but those need to stay within the gamut that is representable in both, and I don't know that it would be a priority to support full gamuts for those color spaces.

Now as to what rendering to a 2D array should mean... *If* the rendered area did not include any ticks or axes marks or text() or line() or patch() objects with interpolated shading... if, in other words, everything being rendered was exactly representable in terms of the current colormap, then rendering as pseudocolor indices might make sense. It does not take much, though, to destroy this -- for example, there is no current way to specify that plot lines or plot markers are to be drawn in terms of a pseudocolor index. The standard colors such as 'r' are defined as being in a "system colormap" outside of any figure colormap.


Answer by Walter Roberson
on 14 Feb 2011

A way to return multiple outputs from a function in an expression context, without having to resort to using a separate assignment statement.

Even if at the beginning this only allowed selecting one output to return by discarding the leading N outputs, that would help .

This is functionality that cannot be written at the user level.

  0 Comments


Answer by Walter Roberson
on 14 Feb 2011

eval() a char array or cell-string array as a multi-line input, allowing continuations and multi-line constructs such as

if (condition)
  %do something
else
  %do something else
end

  8 Comments

Bjorn Gustavsson on 3 Mar 2011

Amazing/amusing!
eval(sprintf('for i1 = 1:10,\n if i1>3\n disp(i1) \n else\n disp(''i1'') \n end \n end\n%%a comment\n'))

Ben Petschel
on 12 Nov 2013

I don't understand - statements like

eval('if 1, disp(''a''); else, disp(''b''); end')

work from at least r2010a onwards

Walter Roberson
on 12 Nov 2013

Yes, Ben, but that string does not contain multiple lines. Commas and semi-colons do not mark the end of a line.


Answer by Walter Roberson
on 15 Feb 2011

Short-circuiting vectorized conditional tests. This might require introducing a new keyword.

For example,

x > y/2

would normally compute the entire element-by-element vector x(K) > Y(K)/2, and then that vector would be processed within whatever expression was around it. For example,

find(x > y/2,1,'first')

or

if any(x > y/2)

But logically these don't need the entire vector result, just a single scalar result.

A lot of the time people are working with vectors too short for BLAS to kick in, but long enough that the time savings of short-circuiting would add up.

Imagine, for example, a new keyword "first":

find(first x > y/2)

or

if first x > y/2

"first" could return either 0 or [] if not found; [] would be more consistent, and ~[] is false so ~first would work like ~any(). On the other hand, what it should return so that it works with find() and logic conditions is a good question.

  3 Comments

Jan Simon
on 15 Feb 2011

See these FEX submissions:

http://www.mathworks.com/matlabcentral/fileexchange/27857-anyExceed

http://www.mathworks.com/matlabcentral/fileexchange/26867-anyEq

Royi Avital
on 21 Jun 2013

What's the difference between FEX and MEX?

Walter Roberson
on 21 Jun 2013

FEX is the MATLAB File Exchange. MEX is the MATLAB API and compiling tool for C, C++, and Fortran to interface with MATLAB.


Answer by Walter Roberson
on 17 Feb 2011

Better integration with perl.

Currently it is necessary to write the perl script to a file and invoke perl() on the file name. Arguments after the file name are permitted but not options before the file name. This makes it impossible to use any of the perl command line options, especially the -e option to designate a short in-line script.

For example,

perl -pe 's/^/ /' foo.txt > newfoo.txt

should ideally be accepted just like on shell scripts lines, but people could probably get used to

outstring = perl('-pe', 's/^/ /', 'foo.txt'); if ischar(outstring) fid = fopen('newfoo.txt','w'); fwrite(fid, outstring); fclose(fid); end

Manual redirection is a nuisance, but having to write trivial scripts to a file in full form (without the benefit of -n or -p even) keeps perl from being used to its full benefit.

  0 Comments


Answer by Matt Fig
on 2 Jul 2011

Use of wild cards and regular expressions with GET and SET.

get(gca,'camera*') % Should return 8 properties

  1 Comment

Jan Simon
on 7 Jul 2011

@Matt: Getting the factory and default settings works for the root handle: "get(0, 'factory')". Using "P=get(gca); regexp(fieldnames(P), ...)" is an option, but not comfortable.
If additional fields have been attached to the object by "schema.prop", more than 8 fields are possible (even if this is unlikely).


Answer by Walter Roberson
on 14 Feb 2011

Memory mapping to the bit level.

  2 Comments

Michelle Hirsch
on 17 Feb 2011

Walter - could you elaborate on why you would want this?

Walter Roberson
on 17 Feb 2011

To complete the memory mapping capabilities down to a level equivalent to C's struct()

nb: C does not specify which "end" of a word the bitfields fill from, and C does not specify the size of the "word" for packing purposes, just that if the current field is too wide to fit it will be put in to the next word. It would be good if these factors could be configured during the memory mapping.


Answer by Walter Roberson
on 16 Feb 2011

Explicit fflush()

yeah, I know fseek() to 0 bytes relative to the current position does the same thing in POSIX, but Windows doesn't promise POSIX.

  1 Comment

Walter Roberson
on 17 Feb 2011

And I found evidence suggesting that fseek(1,0,0) and fseek(2,0,0) don't work :(


Answer by Walter Roberson
on 1 Mar 2011

Extend the : operator so that if there is a value on the left side but not the right side, that the implied right limit is 'end', and if there is a value on the right side but not the left side, then the implied left limit is 1.

A(5:) -- to be equivalent to A(5:end)

A(:4) -- to be equivalent to A(1:4)

  2 Comments

James Tursa
on 16 Mar 2011

Like Fortran :)

Walter Roberson
on 16 Mar 2011

All of the greats borrowed from each other ;-)


Answer by Oleg Komarov
on 19 Mar 2011

Axes properties should be kept independent and the level of customization should be similar to excel.

- For instance, when manipualting TickDir or TickLenght it should be possible to differentiate among the effect on the X axes and Y axes.

- Or, when setting Xcolor, it shouldn't propagate to labels or grids!

- It should be possible to add additional X,Y axes w/o creating additional axes objects.

In general I want to have a more specific control over axes properties.

  0 Comments


Answer by Walter Roberson
on 9 Jun 2011

Controlled time limitations.

You could start timers, and the timers could throw error(), but the timers are not parented to a code block so you cannot try/catch to control timeouts.

These time limitations I'm referring to are "non-cooperative", in the sense that the code being invoked should not have to have been written to know the time-out protocol you are using and should not have to check particular state variables or what-not.

Ideally even BLAS-level operations could be interrupted.

For example, I might want to code the equivalent of, "Give eigs() 5 minutes to come up with the solution, but if it hasn't converted by then, stop that approach and hand off to eig()"

Or I might have a function whose workings I am not familiar with. Or perhaps I'm running a unit-test framework or a framework to test class assignments.

Are the MATLAB Contest time limitations not programmable in MATLAB ?

  0 Comments


Answer by Walter Roberson
on 13 Jun 2011

If there is an atan2() function, why isn't there an acot2() function or acos2() or asin2() ?? Equal time for arc functions!

  1 Comment

Andrew Newell
on 13 Jun 2011

We shall overco-o-ome! We shall overco-o-ome! We shall overcome some day-a-a-a-ay!


Answer by Ashish Bhatt
on 12 Mar 2012

I wish matlab could auto insert the white spaces into the expressions. For example, if I write a+b in an m-file or script, matlab would be able to make it a + b that will save a lot of effort entering white spaces before and after every operator which I am not accustomed to. I am not sure if this functionality is there in other similar software.

  3 Comments

Jan Simon
on 12 Mar 2012

This will be dangerous in Matlab, which accepts some sloppy syntax. E.g. [a+b], [a +b] and [a + b] are different.

Sean de Wolski
on 12 Mar 2012

@Jan, agreed - very dangerous.

@Ashish, you could write a function to this if it is very important to you. Just what you do here:

fprintf('I sometimes use C+%s','+')

?

Daniel
on 19 Mar 2012

I personally would love some sort of formatting help in the MATLAB editor. Maybe auto formating of whitespace (as long as it doesn't get it wrong) like it does with tabbing, or maybe mlint warnings:

This project uses spaces after assignments (a = b;)
This project uses spaces between operators (a + b;)
This project requires commas followed by spaces ([a, b, c])

Where I can set the coding style. Also auto warnings on name clashes (yes mlint should know the name of ALL MATLAB functions) and camelCase etc.


Answer by K E
on 16 Jul 2012

I wish that when I use cell execution (CTRL-Enter from within a cell), the cell's commands would appear in the History and could be accessed by the up arrow or command completion (type first few characters of command then up arrow). If I am tinkering with commands on the command line, I have to copy/paste the commands in order to access them again later.

  1 Comment

craq
on 3 Apr 2013

sorry, but I've got to disagree with you there. I like to keep my cells and command line separate. If I want to move them across, copy/paste is very fast


Answer by Ken
on 6 Feb 2013

What is missing in MATLAB?

Here is my quick thought for today (and most days when editing large sequences of code) :

In the native editor, it is nice when clicking on the if, try, for, etc... beinning construct or the end statement and it reference the line that may be far off the screen for it paired construct beginning/end but why hasn't anyone implemented the begging construct highlight to also include any of the else/catch in between constructs?

It would be nice when reviewing someone else's code to simply click on the beginning logic construct and see all sub blocks (if any) along with the location of the end construct statement.

  1 Comment

craq
on 3 Apr 2013

I wondered that myself, especially since clicking on the else will show you the corresponding if. I'd add switch/case to your list.


Answer by Jim Hokanson
on 11 Apr 2013

Create a formal website for Matlab suggestions.

This isn't necessarily for Matlab as much as it is TMW in general, but what's really missing is a more appropriate setup for this type of question. I would really like to see TMW take on National Instruments model of the NI Idea exchange.

I realize this question, and similar questions like it, are perhaps meant to be banter or office discussion topics or whatever, but I think in some small way some people may hope that these answers influence company policy. As Doug points out (Answer by Doug Hull on 14 Feb 2011), the only official way to try and do this is through the enhancement request. Having submitted many enhancement requests myself, I find this route very unsatisfying.

I would prefer these requests to be public with their own rating system, similar to the NI idea exchange. I think this is a much more satisfying approach for users to provide feedback and provides TMW with the ability to see how other users feel about the suggestion. It might also be more obvious to users and encourage more participation if something formal like the idea exchange existed, instead of hiding enhancement requests behind support or in answers to random questions in the Answers section of the website.

Here's a link to the idea exchange I find the most relevant (NI Labview) but a google search may provide a more persistent link ...

http://forums.ni.com/t5/LabVIEW-Idea-Exchange/idb-p/labviewideas

  0 Comments


Answer by per isakson
on 12 Sep 2013
Edited by per isakson
on 12 Sep 2013

The Find Files Tools does not honor multi-line comments. I wish it did.

I use multi-line comments to comment out "old" code that I want to keep temporarily. (I know, I should learn and trust a version control tool.) Multi-line comment is much better than single line comments because chunks of commented out code may be folded.

Example:

    %{
    cnx(jj).MaxSimulationElapseTime = test_request.MaxSimulationElapseTime;
    und so weiter 
    %}

and when folded

    %{...%}

In the search result for "MaxSimulationElapseTime" I cannot see that this line is commented out.

Since I believe this would be easily fixed, I find it very frustrating.

  0 Comments


Answer by Jeff
on 14 Feb 2011

Zero-based indexing. Also, n-based indexing. See: http://tinyurl.com/ygqmmg5

It would make some things so much easier to program.

I'd also like a goto command. Not that I would use it all that often, but I can't stand the pseudo-intellectuals who insist that using 'break', and having to figure out where the break jumps to, is cleaner than saying 'goto' (and I would use it occasionally).

  16 Comments

Jan Rubak
on 15 Feb 2011

@Jan Simon: Heheh, but my employer would be wont to indent me back.

I'm not sure I take your meaning on zero-based indexing, or the relevance of FAQ4.6. No matter, I'm not really holding my breath for that one anyway, since it's mainly a convenience issue and probably not worth the incidental confusions that it would introduce.

Interesting thoughts on GOTO. You obviously program at a much deeper level than I do.

dpb
on 28 Aug 2013

That there are reasons to avoid indiscriminate GOTOs is unarguable; that there should be a "nanny-state" language restriction that enforces it completely such that the occasional useful places can't be is, simply, just wrong. It's the programmer's job, not the language's.

I'm also in favor of variable-based indexing, not just zero.

dpb
on 29 Aug 2013

I disagree w/ the conclusions of Jan that GOTO really has major detrimental effects regarding optimization and so on. Fortran has dealt with it for ages and all a break is is a GOTO, anyway, just w/ a particular target.

IF, CASE and the like generally end up as GOTOs (JMP, BRA, etc.) as well, in the end...


Answer by Walter Roberson
on 14 Feb 2011

typecast to and from char. It is silly to have to use something like

typecast(uint16(String+0),DestinationClass)

  4 Comments

James Tursa
on 16 Mar 2011

The current version only works with numeric types. I will have to look into the feasibility of including non-numeric types. May have to hack other parts of the mxArray (like the flags) to get this to work.

Jan Simon
on 17 Mar 2011

@James: Your TYPECAST can easily expanded to mxChar arrays.

James Tursa
on 21 Mar 2011

New version is now posted that supports char and logical types. I *think* I got the flags set correctly for this. The main restriction is that you can't typecast from a complex input into a char or logical because that would open up the door for a memory leak. You *can* typecast non-(0 or 1) values into a logical, and MATLAB seems to be able to display and handle them correctly, but caveat emptor on that one.


Answer by Walter Roberson
on 14 Feb 2011

An ability to directly call routines written in another language by having a Matlab-level wrapper that took a structured description of how to marshal the arguments and unmarshal the results. Even if in the first version it was only usable to pass read-only values, it would make calling external routines much simpler.

  2 Comments

Philip Borghesani on 14 Feb 2011

This sounds like LOADLIBRARY to me. How is what you want different from what currently exists?

Walter Roberson
on 14 Feb 2011

I hadn't seen that before, but when I go through it it appears to me that there a a bunch of limitations that are not necessary.

One of them is that for the 64 bit version of Matlab you have to have a C compiler to use it. There appear to be others but I need to look more closely to see if there are ways to overcome the limits that I just didn't notice.


Answer by Walter Roberson
on 14 Feb 2011

When I wraptext() inside a uicontrol, I expect it to take in to account the pop-up arrows and scroll-bar widths, so that I can wrap against my real control and then just set() the String to that result. Instead I had to use trial and error to figure out the width of each of those items and build a wrapping routine that knows the fudge-factors for each of the kinds of controls :(

  0 Comments


Answer by Walter Roberson
on 14 Feb 2011

Maple and Mathematica are both able to create parseable data structures representing graphics -- data structures that are easily turned in to text and writable, and easily readable from files. Sometimes this kind of data structure manipulation of graphics is very useful. When I write in Maple, it is not uncommon for me to compute the structure and contents that I want.

  2 Comments

Andrew Newell
on 14 Feb 2011

This article on FIG file structures is part of the answer: <http://undocumentedmatlab.com/blog/fig-files-format/>

Walter Roberson
on 14 Feb 2011

Thanks, Andrew, I'll look it over further.


Answer by Walter Roberson
on 14 Feb 2011

Currently in anonymous functions, one can execute multiple commands by using [command1, command2, command3] or other such tricks. This does not, however, work if one of the commands returns no arguments. It would help if there was a way to indicate that one wanted to execute a command that normally returned nothing and have it return (e.g.) the empty array as a place holder. A way that wasn't as nasty as evalc()

I tried feval() but that doesn't do the trick.

  1 Comment

Walter Roberson
on 17 Feb 2011

David Young showed a trick with regexp,
http://www.mathworks.com/matlabcentral/answers/1455-hump-day-puzzler
put that's pretty much a more complicated way of using evalc()


Answer by Walter Roberson
on 15 Feb 2011

Along with my suggestions about ?: and about short-circuiting (possibly via a new keyword): some manipulations including ?: and "iterators" can be implemented in terms of an operator that MuPad would call "hold" and Maple would formally call "uneval" (but would normally represent as apostrophes around an expression.)

For example, ?: can be framed in terms similar to

ifelse(condition, hold(expression1), hold(expression2))

where ifelse tests the conditions and then evaluates the first expression if it is true but evaluates the second expression if the condition is false, with the effect of the other expression suspended while it is passed as an argument. hold() of an expression need not be the same as eval(), in that eval() expects a quoted string, but hold() can build a pcode'd execution object with all of the scoping appropriate. Perhaps not so different than

@() expression

but hopefully with nicer semantics than assignin() for affecting state variables (e.g., for iterators)

This leads in to some other ideas I have that are probably worth a separate answer.

  0 Comments


Answer by Oliver Woodford
on 16 Feb 2011

More efficient compilation of MATLAB code to avoid memory churn (hence slower computation) of large arrays.

Examples:

B = exp(-(abs(sin(A)) .^ 2)) / (2 * pi);

could be compiled as a one complicated operation computed on each element of A in turn. More cleverly, for

M = any(sum(abs(A), 2) < 1);

compute the sum(abs(A), 2) one row at a time, do the comparison one element at a time, and exit when the first true element is found. I could go on.

Such improvements to the JIT compiler would be fairly simple, I reckon.

  3 Comments

Jan Simon
on 17 Feb 2011

The JIT compiler cannot be sure, that the functions inside the SUM have no side effects. Imagine ABS is overloaded by a private function, which prints the value to the command window in addition. Then abbreviating the inner loop would change the results.

Walter Roberson
on 17 Feb 2011

JIT can make explicit tests that the functions are built-in's known to have no side-effects, optimize that path, and have the more general path if the preconditions are not satisfied.

This could lead to mark-up in functions that promised no side effects -- and mlint could catch the obvious side-effects like disp() or assignin() or error(), and warn for suspicious constructs. error() is a tricky one, as the argument parsers widely used have to error() if the conditions are not met.

In theory, JIT could build a catalog of argument type combinations that are safe-ish for any given routine. "unconditionally safe" if all paths through the function depend only on the argument types and not (or if a path that depends on the values can be proven not to have side effects for any combination of values.) "Conditionally safe" if a particular combination of types worked but value-independence could not be reasonably proven. "Unsafe" if the combination of types was known to provoke a side effect.

"unconditionally safe" could be optimized for that type combination. "Unsafe" for that combination could not be. I'm not certain at the moment what the best behaviour would be for "conditionally safe" for a type combination.

Jan Simon
on 14 Sep 2012

The check for side-effects must be performed dynamically. Example:

f = input('Type in folder name', 's');
addpath(f);
M = any(sum(abs(A), 2) < 1);

If the added folder contains a user-defined abs.m, the JIT must check on the fly if it is free of side-effects. Of course "abs.m" could contain the next addpath()... I assume a "clear abs" is required to enable the new function. But this should only demonstrate, that the JIT have to be extremely smart when it should detect side-effects.


Answer by Walter Roberson
on 17 Feb 2011

Associative tables, such as indexing by string or arbitrary object.

Indexing by string is relatively easy to fit in to current syntax, unless the string happens to be ':' .

Indexing by more complicated objects would require a new index syntax, I suspect.

To a point, indexing by string can be simulated by structures and dynamic field names, where the first character of the field name was fixed (to avoid problems with strings that do not start with alphabetics), and where characters outside the regular range of field characters were percent-encoded with the % itself replaced by underscore, using UTF-8 representation

foo('Hi there‡') -> foo.SHi_20there_E2_80_A1

Likewise, indexing by an arbitrary (non-integer) double can use hex:

foo(pi) -> foo.D400921fb54442d18

There is a natural extension to single (float), and the extension to uintN and intN need not be hard:

foo(uint16(34163)) -> foo.U28573 where the digit after the U ('Unsigned') indicates the number of bytes. 'I' for 'signed'.

If a mechanism was added to delimit strings (e.g., '__' which is not a valid numeric encoding) then one could imagine chaining several together

foo('Hi', pi) -> foo.Shi__D400921fb54442d18

These mappings fail, though, when the encoding gets past the maximum field length, 63 characters.

  3 Comments

Walter Roberson
on 17 Feb 2011

I see a certain similarity to genvarname(), but that does not generate unique mappings. For example, for char(8466) it would generate 0x2112 which would you would not be able to tell apart from the encoding for '!12'

Walter Roberson
on 18 Feb 2011

As specifying the number of bytes for the integral types might not come naturally, and as one might want to extend to bit types that are not logically bit aligned, or for other reasons one might need a fuller descriptor, then I propose to modify the above scheme so that the descriptor is separated from the value with __ and that _ be used to specify components of the descriptor. For example,

D2_3__ might be used as the prefix for a 2 x 3 array of double precision numbers. Yes such an array would exceed 63 characters, but (A) It's the thought that counts? and (B) I have some ideas for extensions to deal with longer indices.

Ben Petschel
on 8 Jun 2011

Does containers.Map have the features you need?


Answer by Andrew Newell
on 20 Feb 2011

The ungroup action for a compound graphics object like lineseries.

  4 Comments

Walter Roberson
on 16 Mar 2011

Although there are some internal differences between lineseries objects and line objects, I have not yet found any practical difference between them. In particular, searching for objects of type 'line' will find lineseries objects.

Walter Roberson
on 16 Mar 2011

Okay, found a difference:

- plot() emits lineseries objects, the handle() of which has one method.

- line() emits line objects, the handle() of which has no methods.

The properties of the two are the same, including the Type, with the exception that a lineseries object adds:
XDataMode XDataSource YDataSource ZDataSource

Walter Roberson
on 8 Jun 2011

I did see in the documentation today that Brushing applies to lineseries objects but not to line objects.


Answer by Aurelien Queffurust on 4 Apr 2011

What is missing from MATLAB?

MATLAB Suggest feature like for Google to avoid error like undefined function ...

As you type in the search box on Google Web Search , Google Suggest offers searches that are similar to the one you're typing. Imagine you would have the same feature in MATLAB, if you type for example helpa instead of help , you get the following error message:

>> helpa rand
??? Undefined function or method 'helpa' for input arguments of type 'char'.

MATLAB Suggest feature will suggest to type help rand instead !

Blog MATLAB geeks

  1 Comment

Sean de Wolski
on 9 Aug 2013

This exists starting in R2012b.


Answer by Walter Roberson
on 7 Jun 2011

perl-like "interpolation" in strings.

For example, andrei coded

result = evalin(symengine,['simplify(' , char(expr),',exp)']);

This would have been much easier to write if it could have been done as

result = evalin(symengine,'simplify(${char(expr)},exp)');

or maybe

result = evalin(symengine,'simplify(${expr},exp)');

or with sufficient context matching,

result = evalin(symengine, 'simplify($expr,exp)');

(expr was a symbolic expression in the context.)

Interpolation is supported to a very limited extent, in regexp() and regexprep(). It is an important perl operation and it can make string construction a lot easier.

  0 Comments


Answer by Walter Roberson
on 21 Jul 2011

fseek() cannot move past the last byte in a file, contrary to POSIX.1 .

fseek() past end of file is not an error in POSIX.

Requesting a read operation at that point is not an error but does result in the end-of-file flag being set.

Requesting a write operation at a point after end of file is conceptually equivalent to zero fill between the previous end of file and the position of the new data, except that OS's and file systems are allowed to use "gaps" with no backing disk space in the file meta-information; these are traditionally referred to as "holey files", and can be very important for the efficient implimentation of databases.

Any fseek() clears the error flag and the end of file flag from the stream, even if the system can detect that the new position would be after the end of the data actually written.

If there was any data waiting to be written out in the stream, such as if C's fwrite() or fgetc() buffered I/O had buffered data, then the data must be flushed before fseek() returns (unless perhaps asynch I/O was being used; I would need to check that.)

fseek() also handles whatever internal house-keeping is necessary so that on read/write streams, after the fseek() [no matter where to], the stream is in a state where reading or writing could be the next operation.

Reference: POSIX.1-1990 6.5.3 .

This problem was hit "in the wild" when someone fseek()'d to a few bytes in to a new file (skipping a binary header whose contents were to be determined later) and wrote data, and then was confused when fopen() + fseek() + fread() read in bogus data: the initial fseek() past end of file had silently failed so the data was being written from the beginning of the file rather than after the expected gap.

Workaround: None possible except to keep internal track of where one is supposed to be, and if/when an fwrite past end of file is done, go back to the current end of file and fwrite zeros to the current position and then allow the fwrite to proceed. If there are opaque subroutines that might move the file position, this method will not work -- at least not without overloading the I/O operations.

  0 Comments


Answer by David Goldsmith on 13 Sep 2011

Support for arrays of formats in datetick, e.g., I'd like datetick to be able to produce time axes like:

        |        |        |        |        |        |        |
   09/12 00:00 06:00    12:00    18:00 09/13 00:00 06:00    12:00

by passing in something like {'mm/dd HH:MM', 'HH:MM'} for the dateform argument. (In contemplating writing this myself, I realize it is non-trivial to make such a thing robust to the variety of arrays users might try to throw at it. On the other hand, there is nothing to stop MATLAB developers from deciding on a syntax/outcome they will support and then define that in the help string: IMO, something along these lines would be better than the monochromatic status quo.)

  1 Comment

Walter Roberson
on 13 Sep 2011

I think "monochronlogic" might perhaps be a more appropriate adjective than "monochromatic".

I think there ought to be an adjective "monochronatic" ;-)


Answer by David Goldsmith on 3 Oct 2011

"something you can do with other similar software but can't with MATLAB"

In a separate pane in the Editor window, see an expandable list of "structures" (in a generalized sense, i.e., including functions, structs, classes, imported modules, etc.) present in the currently visible tab. (I'm not as familiar w/ other IDE's as I'd like to be, but I know that Stani's Python Editor has a feature like this, IIRC, so does MS Visual Studio, and I think Eclipse does also.)

  0 Comments


Answer by Walter Roberson
on 8 Oct 2011

Currently, "i" and "j" can be used as numeric suffixes to denote the imaginary unit.

This parsing could be extended to include pi, such as allowing someone to write

for k = 0:0.01:2pi

Of course, as 2pi is itself numeric, it should be suffixable with "i" or "j", leading to (e.g.)

exp(-2pii)

  2 Comments

Jan Simon
on 8 Oct 2011

pii=3; exp(pii);
Do you expect -1 or 20 as result?

Walter Roberson
on 8 Oct 2011

Same rules as for "i" and "j" : the interpretation is only in effect when used as a suffix.


Answer by Andrew Newell
on 25 Jan 2012

An equivalent of the UNIX command wc that allows one to determine useful information about the size of a file before reading it.

  1 Comment

Walter Roberson
on 26 Jan 2012

wc reads the file ;-)

What I think people would appreciate is a command that would indicate how many columns a file had. With optional header lines and optional field delimiter.


Daniel