Digital Signal Processing Reference
In-Depth Information
The last two examples show how to access column 1 and row 1, respectively.
2.3.2
Number Ranges
A variable can hold a range of numbers. For example, imagine that variable N
should hold all numbers 1, 2, 3, 4, etc., up to the number 100. Here is one way to
create N:
for index=1:100
N(index)=index;
end
This does the job, but there is a faster and simpler way to say the same thing.
Below, we set N equal to a range, specied with a colon \:" symbol between the
starting and ending values.
N=1:100;
If a third number is specied, then the second one will be used as the increment.
For example, M=0:0.4:2 would assign the sequencef0, 0.4, 0.8, 1.2, 1.6, 2gto
variable M. The following example shows all numbers between 8 and 20, with an
increment of 2.
>> 8:2:20
ans =
8
10
12
14
16
18
20
2.3.3
Output
Often, during a program's run, the program needs to convey information to the
user. To print a string or a number to the screen, the sprintf command is quick
and simple.
>> sprintf(The value of pi is %5.3f, pi)
ans =
The value of pi is 3.142
Search WWH ::




Custom Search