Re: Matlab is not a real array oriented language.



reza wrote:
Thats right. Matlab lacks abstraction at the most fundamental level.
For example the language doesnt abstract arrays correctly; to matlab
everything looks like a matrix, even scalars and vectors. To matlab a
scalar is a 1x1 matrix and a vector is a matrix with 3 rows and a
single column.

a = 1;
size(a)

ans =

1 1

a = 1:3;
size(a)

ans =
3 1

The first call to size() should return 0 and the second call should
return a 3.

Dimension higher than 2 are handled incorrectly; the size of a 3-d
array in matlab is rows x cols x depth, where as it should be depth x
rows x cols. The dimension of any array regardless of its size starts
with row x col. I suspect this is a nasty inheritance from the time of
Fortran programmers where arrays were column-wise.


Here is an example of how matlab does not take care of boundary
conditions correctly:


m = rand(3,4); size(sum(m))
ans =

1 4

m = rand(2,4); size(sum(m))
ans =

1 4

m = rand(1,4); size(sum(m))
ans =

1 1


The last call should return [1 4], but it suddenly sum() flips the
axes! Why?

Am I the only one who finds these behaviours annoying?

/reza


At the risk of fanning any flames, I'll hop in. As Steve Lord
mentioned, many of us at MathWorks are listening. And we constantly
face the dilemma of compatibility vs. improving the language.

In the case of sum, and the other "reduction" functions (those that
reduce the effective dimensionality), when we moved to n-dimensions in
version 5, the rule we used was to continue to operate on the first
non-singleton dimension. This is very convenient for command-line
doodling. But as you noticed, this causes programmers the need to
program defensively. That itself can be error-prone, and certainly
annoying, since you'd rather spend time on the guts of the algorithm.
For that reason, sometime since then, and I don't remember when, we
added an extra input argument, e.g.,

B = sum(A,dim)

so the programmer could specify the dimension to work along and have
reliable code without so many contortions. We continue to look for such
opportunities.

We also have been discussing code transition ideas here. We continue to
look at this -- and have not abandoned the idea. However, projects like
this take their own time as well.


--Loren
http://blogs.mathworks.com/loren/
.



Relevant Pages

  • Re: Matlab is not a real array oriented language.
    ... For example the language doesnt abstract arrays correctly; to matlab ... Dimension higher than 2 are handled incorrectly; ... Fortran programmers where arrays were column-wise. ... this causes programmers the need to program defensively. ...
    (comp.soft-sys.matlab)
  • Re: Matlab is not a real array oriented language.
    ... For example the language doesnt abstract arrays correctly; to matlab ... Dimension higher than 2 are handled incorrectly; ... Fortran programmers where arrays were column-wise. ...
    (comp.soft-sys.matlab)
  • Re: What am I doing wrong here
    ... what you are saying doesnt make sense. ... Now these two arrays have different size than x. ... Matlab will give you an error ... since dimension of A is not equal to dimension of x. ...
    (comp.soft-sys.matlab)
  • Re: gfortran & adjustable array: most values remain zero
    ... Indeed I expected that adjustable arrays would work in 2D the same ... adjustable arrays of more than one dimension should be generally avoided ... the actual and dummy arrays don't ...
    (comp.lang.fortran)
  • Re: Out of memory error under 64-bit vista
    ... I have successfully installed MATLAB 2007a on a quad core ... 64-bit machine running Vista Business. ... compile files using Microsoft Visual Studio 2005. ... small arrays, ...
    (comp.soft-sys.matlab)

Loading