Download 3 - McMaster Physics and Astronomy

Transcript
Example — Reading a URL
is, to return to variable isr an object that can read characters. Then,
the java.io.BufferedReader constructor is called with isr, to return
a BufferedReader object to variable br. A buffered reader provides for
efficient reading of characters, arrays, and lines.
isr = java.io.InputStreamReader(is);
br = java.io.BufferedReader(isr);
4 Read and display lines of text.
The final statements read the initial lines of HTML text from the site,
displaying only the first 4 lines that contain meaningful text. Within the
MATLAB for statements, the BufferedReader method readLine reads
each line of text (terminated by a return and/or line feed character) from
the site.
for k = 1:259
s = readLine(br);
end
% Skip initial HTML formatting lines
for k = 1:4
s = readLine(br);
disp(s)
end
% Read the first 4 lines of text
Running the Example
When you run this example, you see output similar to the following. (Note
that the line breaks were changed to fit the output in the documentation).
<p>This technical note provides an introduction to vectorization techniques.
In order to understand some of the possible techniques, an introduction to MATLAB
referencing is provided. Then several vectorization examples are discussed.</p>
<p>This technical note examines how to identify situations where vectorized techniques
would yield a quicker or cleaner algorithm. Vectorization is ofen a smooth process;
however, in many application-specific cases, it can be difficult to construct a vectorized
routine. Understanding the tools and
7-73