MATLAB POLYSPACE RELEASE NOTES Instrukcja Użytkownika Strona 50

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 240
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 49
2 Matrices and Arra ys
This kind of subs cripting can be do n e in one step by specifying the logical
operation as the subscripting expression. Suppose you have the following
set of data:
x = [2.1 1.7 1.6 1.5 NaN 1.9 1.8 1.5 5.1 1.8 1. 4 2.2 1.6 1.8];
The NaN is a marker for a mis sing observation, such as a failure to respond to
an item on a questionnaire. To remove the missing data with logical indexing,
use
isfinite(x), which is true for all finite numerical values and false for
NaN and Inf:
x = x(isfinite(x))
x=
2.1 1.7 1.6 1.5 1.9 1.8 1.5 5.1 1.8 1.4 2 .2 1.6 1.8
Now there is one observation, 5.1, which seems to b e very different from the
others. It is an outlier. The following statement removes outliers, in this case
those elements more than three standard deviations from the mean:
x = x(abs(x-mean(x)) <= 3*std(x))
x=
2.1 1.7 1.6 1.5 1.9 1.8 1.5 1.8 1.4 2.2 1 .6 1.8
For another exam ple, highlight the location of the prime numbers in Dürer’s
magic square by using logical indexing and scalar expansion to set the
nonprimesto0. (See“ThemagicFunction”onpage2-9.)
A(~isprime(A)) = 0
A=
03213
50110
0070
0000
The find Function
The find function determines the indices of array eleme nts that meet a given
logical condition. In its simplest form,
find returns a column vector of indices.
Transpose that vector to o btain a row vector of indices. For example, start
again with Dürer’s magic square. (See “The magic Function” on page 2-9.)
2-28
Przeglądanie stron 49
1 2 ... 45 46 47 48 49 50 51 52 53 54 55 ... 239 240

Komentarze do niniejszej Instrukcji

Brak uwag