JCB30304 Data Acquisition System: Chapter 2: Basic Programming Miss Nur Fazira Haris

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

LECTURE 4:

JCB30304
DATA ACQUISITION SYSTEM
CHAPTER 2 : BASIC PROGRAMMING
MISS NUR FAZIRA HARIS
CHAPTER 2
 MATLAB Script
MathScript
 The “LabVIEW MathScript Window” is an interactive interface in which you
can enter .m file script commands and see immediate results, variables and
commands history. The window includes a command-line interface where
you can enter commands one-by-one for quick calculations, script
debugging or learning. Alternatively, you can enter and execute groups of
commands through a script editor window.
 You can use the “LabVIEW MathScript Window” to enter commands one at
time. You also can enter batch scripts in a simple text editor window, loaded
from a text file, or imported from a separate text editor. The “LabVIEW
MathScript Window” provides immediate feedback in a variety of forms,
such as graphs and text.
LabVIEW MathScript
 Combine textual math
and graphical
programming
 Reuse many of your m-
file scripts created with
The MathWorks, Inc.
MATLAB® software
What Is LabVIEW MathScript?
Powerful textual programming for
signal processing, analysis, and math
More than 650 built-in functions
Reuse many of your m-file scripts created
with The MathWorks, Inc. MATLAB® and others
Based on original math from NI MATRIXx

A native LabVIEW solution


Interactive and programmatic interfaces
Does not require third-party software
MathScript Features
MathScript Feature Description

Powerful Textual Math Over 650 built-in functions for math, signal processing and analysis

Math-Oriented Syntax Matrices and arrays are fundamental datatypes.


and Datatypes Largely support vectorized operations

Compatible Generally compatible with the widely used m-file script syntax

Extendible Define custom functions

Part of LabVIEW Does not require third-party software to compile and execute

Programmatic LabVIEW
Combine graphical & textual code programming
Interface
MathScript Details
 Part of the Full, Professional, Student and Evaluation
editions of LabVIEW, for Windows platforms only
(no Linux, Mac, RT, etc.)
 MathScript is NOT a standalone replacement for
alternative technical computing software
 Third
party toolboxes are not supported
 Some commands and variable types are not supported
How do I use Mathscript?
 MathScript can be used in two ways

 In a MathScript window as a desktop mathematical tool


independent of LabVIEW

 In a MathScript node which appears as a frame inside the


Block diagram of a VI (available on the Functions /
Mathematics / Scripts & Formulas palette.)
MathScript Window Components
Output Window

Workspace

Selected Variable

Command Window

Getting Started
Window
The MathScript Window : Variable View
The MathScript Window : Script Tab
 Interactively develop and
test scripts and functions Right Click
Pop-up
with the Script Editor Menu
 Enter / Edit script text
 Save & Compile / Save /
Load / Run scripts
 Launch separate Script
Editor window for easy
editing
The MathScript Window : History Tab

Right Click to
Clear History
Exercise 1
In the MathScript window,
 Create an array 𝑎 = 1,2,3,4,5.

 Create an array 𝑏 = 2,4,6,8 … 20.

3 9
 Define the matrix .
6 −5
Exercise 2
Given the vector:
>>x=[1 2 5 6 8 9 3]
→ Find the mean value of the vector x.
→ Find the minimum value of the vector x.
→ Find the maximum value of the vector x.
Example: Plotting
 Function plot can be used to produce a graph from
two vectors x and y.
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
Exercise
Exercise: Plotting
MathScript Node
 Embed MathScripts into LabVIEW code
on the block diagram
 Populate with m-file script text
 Type m-file scripts directly into the node
 Import from files
 Create inputs/outputs on node edges
MathScript
 MathScript compiles script when run Node
 Unlike MATLAB® script nodes, MathScript
script nodes do not require third-party
software
MathScript Node
m-Script
MathScript
Node

Right-Click Menu
Programmatic Math with the MathScript
Node
 Combine graphical system design with textual math
 Deploy with LabVIEW graphical programming
 Implement equations and algorithms with text
Goal: Multiple Programming Approaches

Freedom to choose the best approach Reuse your existing code

Add interactive user interfaces to your Integrate math with real-world I/O and
algorithms instrument control
LabVIEW Mathscript
 A LabVIEW tool for executing textual mathematical commands

 Matrix and vector based calculations (linear algebra)


 Visualization of data in plots
 Running scripts containing a number of commands written in a file
 A large number of mathematical functions. An overview is given later in
this document.
 MathScript command are equal to MATLAB commands (some MATLAB
commands may not be implemented).
Example :Plotting a sine wave
Example : Embedded Mathscript

Tip: Get MathScript module


from Functions tools, under
K 1
T   T   273.15 T  Programming/Structures
C K

A  B ln R   Cln R 
3
Creating a LabVIEW MathScript
THANK YOU

You might also like