Sep 21, 2009

MatLab: Study

MATLAB operators:
---------------

1. Colon operator:
---------------
J:K is the same as [J, J+1, ..., K].
J:K is empty if J > K.
J:D:K is the same as [J, J+D, ..., J+m*D] where m = fix((K-J)/D).
J:D:K is empty if D == 0, if D > 0 and J > K, or if D < 0 and J < K.

COLON(J,K) is the same as J:K and COLON(J,D,K) is the same as J:D:K.

The colon notation can be used to pick out selected rows, columns
and elements of vectors, matrices, and arrays. A(:) is all the
elements of A, regarded as a single column. On the left side of an
assignment statement, A(:) fills A, preserving its shape from before.
A(:,J) is the J-th column of A. A(J:K) is [A(J),A(J+1),...,A(K)].
A(:,J:K) is [A(:,J),A(:,J+1),...,A(:,K)] and so on.

The colon notation can be used with a cell array to produce a comma-
separated list. C{:} is the same as C{1},C{2},...,C{end}. The comma
separated list syntax is valid inside () for function calls, [] for
concatenation and function return arguments, and inside {} to produce
a cell array. Expressions such as S(:).name produce the comma separated
list S(1).name,S(2).name,...,S(end).name for the structure S.

For the use of the colon in the FOR statement, See FOR.
For the use of the colon in a comma separated list, See VARARGIN.



2. Matrix transpose operator:
-----------------------
a = ones(1:1:10);
at = a'

' operator transposes a matrix.

3. Details of a variable
------------------
reza = [1]

reza =

1
whos reza

Name Size Bytes Class Attributes

reza 1x1 8 double

4: Cell function:
------------------
    % data_points.labels returns a cell array of +1 and -1
    labels = data_points.label;
    cell_wise_result = cellfun(@(c) find(c == 1), labels, 'uniform', false);
    idx = find(~cellfun(@isempty,  cell_wise_results));

    % updated November, 2018

2 comments:

Anonymous said...

Well....Nice to know about MATLAB on Eid day :D

have a nice time Vaia.. :-)

--Mahmud

Md. Alimoor Reza said...

CS r student ra usually MATLAB posondo kore na. Engineering students (Electrical, Mechanical, Civil, Chemical etc) mainly MATLAB or MAPLE niye kaj kore. Akhon amar research giye dekhi onek numerical analysis MATLAB e kora onek shibidha jonok. Ki ar kora shikhte hochche arki.

Down with the Dictatorship!

    "Let them hate me, so that they fear me" - Caligula 41AD