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

Replacing, Finding, and separating strings: There are numerous functions which find and replace the strings, or parts of strings, within the other strings and functions which

Matrix Multiplication: The Matrix multiplication does not mean multiplying term by term; and it is not an array operation. The Matrix multiplication has a very particular mean

Use of While loop: Here is an illustration of calling the function, passing 5000 for the value of the input argument high. >> factgthigh(5000) ans = 5040 The itera

Execute a exponential function program: Running the script will take up the menu as shown in the figure: Then, what happens will totally depend on which button(s) the

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

Use polyval to evaluate the derivative at xder. This will be the % slope of the tangent line, "a" (general form of a line: y = ax + b). % 4. Calculate the intercept, b, of t

Interpolation and extrapolation: In most cases, it is desired to estimate values other than at the sampled data points. For illustration, we may want to estimate what the temp

Illustration of Matrix solutions: For illustration, consider the three equations below with 3unknowns x 1 ,x 2 , and x 3 : We can write this in the form Ax = b here A

Splits a string : The strtok function splits a string into pieces; it can be called in many ways. The function receives one string as an input argument. It appears for the fir