Page 58 - Applied Statistics Using SPSS, STATISTICA, MATLAB and R
P. 58
2.1 Preliminaries 37
Besides the insertion of new variables, one can also perform other operations
such as sorting the entire spreadsheet based on column values, or transposing
columns and cases, using the appropriate STATISTICA ta Da menu options.
2.1.2.3 MATLAB
In order to operate with the matrix data in MATLAB we need to first learn some
basic ingredients. We have already mentioned that a matrix element is accessed
through its indices, separated by comma, between parentheses. For instance, for the
previous met eo matrix, one can find out the value of the maximum precipitation
rd
st
(1 column) for the 3 case, by typing:
» meteo(3,1)
ans =
101
rd
th
If one wishes a list of the PMax values from the 3 to the 5 cases, one would
write:
» meteo(3:5,1)
ans =
101
80
36
Therefore, a range in cases (or columns) is obtained using the range values
separated by a colon. The use of the colon alone, without any range values, means
the complete range, i.e., the complete column (or row). Thus, in order to extract the
PMax column vector from the meteo matrix we need only specify:
» pmax = meteo(:,1);
We may now proceed to compute the new column vector, PClass:
» pclass = 1+(pmax>20)+(pmax>80);
and join it to the meteo matrix, with:
» meteo = [meteo pclass]
Transposition of a matrix in MATLAB is straightforward, using the apostrophe
as the transposition operation. For the o mete matrix one would write:
» meteotransp = meteo’;
Sorting the rows of a matrix, as a group and in ascending order, is performed
with the rows sort command:
» meteo = sortrows(meteo);