0% found this document useful (0 votes)
20 views

Comparison - Matlab Scripts BASIC

This document compares the programming languages Matlab and BASIC. It outlines several key similarities between their syntax, including how variables are assigned, how to print outputs, and conditional and logical operators. Conditional execution using if/elseif/else statements is also compared, noting they function similarly between the two languages. The document is intended to help familiarize those with BASIC when first learning to write scripts in Matlab.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Comparison - Matlab Scripts BASIC

This document compares the programming languages Matlab and BASIC. It outlines several key similarities between their syntax, including how variables are assigned, how to print outputs, and conditional and logical operators. Conditional execution using if/elseif/else statements is also compared, noting they function similarly between the two languages. The document is intended to help familiarize those with BASIC when first learning to write scripts in Matlab.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

7/4/2014

Comparison: Matlab Scripts & BASIC

Comparison: Matlab Scripts & BASIC


There are many similarities between the language used for Matlab scripts and more the more familiar BASIC
programming language (and other higher level languages such as FORTRAN, Pascalor C). This document may
help when becoming familiar with Matlab scripts.
* * * * * * * BASIC * * * * * * *

* * * * * * * MATLAB * * * * * * *

Variable Assignments
In Matlab, all variable assignments are case sensitive, so the variable Test1is different from the variable
test1. In Matlab, if an assignment is terminated with a semicolon, Matlab does not print out the result. If it
is not terminated by a semicolon, it will print out the results of the assignment (In the Matlab code below,
there is no semicolon after the assignment for A. This causes Matlab to print the answer).
R=2
P = 3.14
A = P*R^2
PRINT A
12.56

R = 2;
P = 3.14;
A = P*R^2
ans =
12.560

Printing
PRINT "Area = ";A;" m^2"

disp(['Area = ' num2str(A) ' m^2']);

Conditional & Logical Operators


=
<>
<
<=
>
>=
AND
OR
NOT

equal
not equal
less than
less than or equal
greater than
greater than or equal
and
or
not

==
~=
<
<=
>
>=
&
|
~

equal
not equal
less than
less than or equal
greater than
greater than or equal
and
or
not

Conditional Execution
The code below shows a simple set of Block-If statements. In some older versions of BASIC, there is no
Block-If structure and so it would have to be done strictly using GOTOstatements.
if Sel = 1 then
print "Selection is 1"
elseif Sel = 2 then
print "Option 2 Here"
else
print "None of the Above
endif

* * * * * * * BASIC * * * * * * *

if Sel == 1
disp('Selection is 1');
elseif Sel == 2
disp('Option 2 Here');
else
disp('None of the Above');
end

* * * * * * * MATLAB * * * * * * *

Next Page
NOTE: This document uses HTML 3.0 Extensions. It must be viewed with an appropriate browser (such as
Netscape Version 2 or higher)
Electronic Copy: http://physics.gac.edu/~huber/matlab/mtlbasic.html
Revised: 27-JAN-1997 by Tom Huber, Physics Department, Gustavus Adolphus College.

http://physics.gac.edu/~huber/matlab/mtlbasic.htm

1/1

You might also like