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
readlenwid function: function call: [length, width] = readlenwid; function header: function [l,w] = readlenwid In the function call, not any argument is passed; henc

Function rmfield - structure: The function rmfield eliminates a field from the structure. It returns a new structure with field eliminated, but does not modify the original st

Examine exponential function: The algorithm for the main script program is shown below:  Call a function eoption to show the menu and return the user's choice.  Loop

Sort algorithm for Sorting vectors of structures: Note that only the price field is compared in the sort algorithm, but the whole structure is replaced. That is therefore each


Variable Scope: The scope of any of variable is the workspace in which it is valid. The workspace generated in the Command Window is known as the base workspace. As we know

Initializing the data structure - Function: Function is shown as:   >> printcylvols(cyls) Cylinder x has a volume of 169.6 Cylinder a has a volume of 100.5

Function used in binary search: The function below implements this binary search algorithm. It receives two arguments: the sorted vector and a key (on the other hand, the func

Appending variables to the Mat-File: Appending to the file adds to what has been saved in a file, and is accomplished by using the -append option. For illustration, supposing

Replacement : Replace a row by adding it to (or subtract from it) a multiple of the other row. For a given row ri, this is written as   ri  - srj →  ri Note that when r