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
Evaluating a string: The function eval is used to compute a string as a function. For illustration, below is the string 'plot(x)'is interpreted to be a call to plot the functi

Algorithm for the function explaine: The algorithm for the function explaine is as shown:  Print a description of e, the exp function, and how to find the approximate va

Write a program to examine exponential function: We will write a program to examine the value of e and the exponential function. It will be a menu-driven. The menu options wil

Finding products by for loop: an illustration, when 5 is passed to be the value of the input argument n, the function will compute and return 1 + 2 + 3 + 4 + 5, or 15: >> s

analyzing traffic; determine motion of flow; calculate tracklets; detect abnormalities;

Data structures: The Data structures are variables which store more than one value. In order to made sense to store more than one value in a variable, the values must in some

I have a 400x2 vel.dat and 20x2 xy.dat file, how can i plot a streamslice graph on matlab with this two files.

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

Forward elimination: In forward elimination, we want to obtain a 0 in the a 21 position. To accomplish this, we can alter the second line in the matrix by subtracting from it

Comparing strings: There are few functions which compare strings and return logical true when they are equivalent or logical false when not. The function strcmp compares the s