Re: Matlab is not a real array oriented language.
- From: Loren Shure <loren@xxxxxxxxxxxxx>
- Date: Tue, 27 Jun 2006 07:41:56 -0400
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:
ans =m = rand(3,4); size(sum(m))
1 4
ans =m = rand(2,4); size(sum(m))
1 4
ans =m = rand(1,4); size(sum(m))
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/
.
- Follow-Ups:
- References:
- Prev by Date: User defined functions-Getting multiple return values.
- Next by Date: real time workshop
- Previous by thread: Re: Matlab is not a real array oriented language.
- Next by thread: Re: Matlab is not a real array oriented language.
- Index(es):
Relevant Pages
|
Loading