DEV Community

dinhanhx
dinhanhx

Posted on

How stupid is Matlab accessing array syntax?

Here is how you define an array and print the first element in it

v = [4 5 6 7];
disp(v(1));
Enter fullscreen mode Exit fullscreen mode

Let not talk about the fact that matlab array starts with 1 for now.

So what's the problem here? The functions also use () for receiving parameters. When you read this line without previous lines, disp(v(1)) you have to ask yourself this question:

  • v is a function or an array?

"I always read the previous lines" you may argue. But can you remember which one is a function, which one is an array in a long script with many functions and variables?

Now you have to remember () has two meanings. Well two usage of () near each other can create confusion.

Top comments (2)

Collapse
 
pandademic profile image
Pandademic

Why is MATLAB like this??

Collapse
 
dinhanhx profile image
dinhanhx

Good question. I guess we never know.