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

Execution steps: Whenever the program is executed, the steps below will take place: The script calcandprintarea starts executing. The calcandprintarea calls the readr

Built-in colormaps: The MATLAB has numerous built-in colormaps which are named; the reference page on colormap shows them. Calling the function colormap without passing any ar

FOR Loop: The for loop, or the for statement, is used whenever it is essential to repeat statement(s) in the script or function, and whenever it is known ahead of time how man

I dont know how to input different videos on matlab program

Matrix solutions to systems of the linear algebraic equations: The linear algebraic equation is an equation of the form a 1 x 1 + a 2 x 2 + a 3 x 3    .  .  .  .  a n x n

Illustration of Preallocating a Vector: Illustration of calling the function: >> myveccumsum([5 9 4]) ans =     5  14  18 At the first time in the loop, outvec wil

Illustration of if - else statement: The one application of an if-else statement is to check for errors in the inputs to a script. For illustration, a former script prompted t

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

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