tags:

views:

35

answers:

1

hi guys i' m noob at matlab and i wonder what the differences array definition for example:

1.) abc=[ 0 0 0 0 0 0]

2.) abc=[0;0;0;0;0;0]
in C ,first definition is  int abc[]={0,0,0,0,0,0};
      second definition is int [6][1]= {{0},{0},{0},{0},{0},{0}};   

am i correct about that? any help will be appreciated.

+4  A: 
abc = [1 2 3 4]

Is a "row vector".

abc = [1 2; 3 4]

Is a 2x2 matrix, because semicolons inside brackets separate rows.

abc = [1; 2; 3; 4]

Is a 4x1 matrix, aka "column vector". It's a special case of a matrix, really. You can also get it by transposing the corresponding row vector:

abc = [1 2 3 4]'

(note the quote at the end - this is the transpose)


P.S.: Yes, your interpretation to C is correct in this case.

Eli Bendersky
thx mrs eli. i am trying to learn matlab, could you say me good resource ?
ibrahimyilmaz
@ironykchel: the Matlab documentation is pretty good, and Googling "matlab tutorial" should do the rest
Eli Bendersky
@ironykchel Find interesting problem and try to solve it :) It's the best way to learn, IMHO.Have you looked at file exchange at matlabcentral webpage? It is sometimes interesting to see how other people solve their problems.
Gacek
I'll add that be careful of ' i.e., the complex conjugate transpose operator. If your data is complex, it produces the conjugate transpose. The .' operator produces a non-conjugate transpose if all you wish to do is change the shape of your array as transpose would do. If your array is real, then they are identical operators.
woodchips
Matlab is also column-major so it is faster to scan down columns than over rows. Column-major order means that elements along a column are sequential in memory while elements along a row are further apart. Scanning down columns promotes cache efficiency.
Elpezmuerto

related questions