Loading in 2 Seconds...
Loading in 2 Seconds...
Use of Matlab for Analysis and Plotting of Accoustic Well Data. Home. Start Matlab M-files. Program Exercise. Operators and comands. Introduction. Resources. Open and converting data. Quiz. Handling graphics. Introduction.
Operators and comands
Open and converting data
MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation
MATLAB is an interactive, matrix based system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar non interactive language such as C or Fortran
However, the speed when running a Matlab script or function may be described as ”slow as a turtle” compared to Fortran (”fast as a rabbit”)
The name MATLAB stands for MATrix LABoratory. Matlab may …
MATLAB may be used directly from the command window, but you should use m-file programming. This is quite similar to Fortran programming but the file is denoted .m rather than .f
There are two types of m-files; scripts and functions, where the first is the simplest and easiest-to-use.
When you invoke a script, MATLAB simply executes the commands found in the file. Scripts can operate on existing data in the workspace, or they can create new data on which to operate. In addition, scripts can produce graphical output using functions like plot.
There are two ways you can start Matlab:
Creating m-files in:
Running m-files: type the name of the file (without .m; if the filename is test.m, type test) in the matlab command window and hit enter (both Windows and Unix)
When you have created an m-file, you should start your script by opening the file from which your data is to be imported
For a file in ASCII format use the following command:
fp = fopen( ’c33.dat’ , ’ r ’)
opens the file c33.dat and labels it fp
For control of your data you should convert it into a matrix
To do so, you should use the command
[w,c] = fscanf(fp,'%e %e %e %e %e %e %e %e',[8, inf])
reads data from fp in e-format (%e) into the matrix w that has 8 columns and unknown number of rows (8, inf)
Arithmethic operators in matlab are the familiar expressions:
+ - / * ^
Note: If you want to perform an element by element operation of two or more matrices, instead of / * ^, use ./ .* .^
If you want to extract the first column from a matrix x and store it as the variable v, use the following command:
z = x(1,:)
If you want to make a new vector acimp(i)=vp(i)*rho(i), use:
acimp = vp.*rho
where vp and rho has already been defined
MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs
Creating a plot:
plot(x, y) produces a graph of y vs x
Multiple graphs in one figure:
plot(x1, y1, x2, y2, ...)
Typically, you often want to plot several different plots in different windows for easy comparison. To do so use the command:
figure(n) where n is the number of the figure
Colors and Styles
It is possible to specify color, linestyle, and markers, such as plus signs or circles, with:
Color strings are 'c', 'm', 'y', 'r', 'g', 'b', 'w', and 'k'. These correspond to cyan, magenta, yellow, red, green, blue, white, and black.
Linestyle strings are '-' for solid, '- -' for dashed, ':' for dotted,
'-.' for dash-dot, and 'none' for no line.
The most common marker types include '+', 'o', '*', and 'x'.
plots a cyan, dotted line and places plus sign markers at each data point
The subplot function allows you to display multiple plots in the same window:
breaks the figure window into an m-by-n matrix of small subplots and selects the p’th subplot for the current plot.
Subplots are best illustraded with an example
About the author
For more general questions and definitions try these
Schlumberger Oilfield Glossary
”Getting started with Matlab”
Subsequent to this module you should...
See the plots this matlab script would produce: