Reading from a file in a while loop, MATLAB in Engineering

Reading from a File in a While Loop:

Though in most languages the combination of a loop and an if statement would be essential to determine whether or not the elements in a vector are logical true, the MATLAB has built-in functions like any, all, and find to accomplish the tasks.

For illustration, the data from an experiment has been recorded in a file known as 'experd.dat'. The file has few numbers followed by a -99 and then more numbers, all on the similar line. The only data values which we are interested in, though, are those before the -99. The algorithm for the script will be as shown:

1.  Read the data from file into the vector.

2.  Generate a new vector variable newvec which has the data values only up to but not involving the -99.

3.  Plot the new vector values, by using black o's.

 

For illustration, if the file has the following:

3.1 11 5.2 8.9 -99 4.4 62

the plot generate would look like figure as shown below:

 

817_Reading from a File in a While Loop.png

For ease, we will suppose that the file format is as specified. The load will generate a vector with the name experd that contains the values from the file. As this is also a generic data we will omit the plot labels and titles for simplicity.

 

Posted Date: 10/19/2012 6:07:16 AM | Location : United States







Related Discussions:- Reading from a file in a while loop, Assignment Help, Ask Question on Reading from a file in a while loop, Get Answer, Expert's Help, Reading from a file in a while loop Discussions

Write discussion on Reading from a file in a while loop
Your posts are moderated
Related Questions
Preallocating a Vector: There are necessarily two programming techniques that can be used to simulate the cumsum function. One technique is to begin with an empty vector and c

Algorithm for the function e: The algorithm for the function eoption is as shown: Use the menu function to show the 4 choices. Error-check (an error would take place

Passing arguments to functions: In all these functions examples faraway, at least one of the arguments was passed in the function call to be the value(s) of the equivalent inp

Finding a sting - function strfind: The function strfind does necessarily similar thing, except that the order of the arguments does make dissimilarity. The common form is str


Passing Structures to Functions: The whole structure can be passed to a function, or separate fields can be passed. For illustration, here are the two distinct versions of a f

Finding a sting - function findstr: The function findstr receives two strings as input arguments. It finds all the occurrences of shorter string contained by the longer, and r

Gauss, Gauss-Jordan elimination: For 2 × 2 systems of equations, there are well-defined, easy solution techniques. Though, for the larger systems of equations, finding solutio

Example of Interpolation and extrapolation: The MATLAB has a function to do this, known as polyfit. The function polyfit finds the coefficients of the polynomial of the partic

. Generate the following signal, x(n)=1+cos((25*pi*n)/100),0 Compute the DTFT of x[n] for w=0:0.01:2*pi Plot the Real part, imaginary part, the amplitude and phas