Work Using Matlab Files

Work using Matlab files are often used by experts programmer. Advantage to work with matlab files that will allow you debug the entire program. Especially for long script program and it takes long time to compelete.

To use matlab file or M file, just type "edit" in command window and press enter to call Matlab Editor. After that, you can type your program in Matlab editor. In this example we can use the following program:

%-----------------------
%Training Program 1
%Matlab Programming
%----------------------

clear all;
clc;

disp('-----------------');
disp('Training Program 1');
disp('-----------------');

length = 5;
width = 5;
area = length*width;
disp(['area ->' num2str(area)]);


Copy or type program above to your Matlab editor. After that save it as training01.m to c:/mytraining directory. Back to Command Window and type "cd c:/mytraining". This is done in order that Matlab recognize our Matlab file location.

Press enter and type our matlab file name (training01) .

Press enter and the program will be executed. output result will be shown as follows :

-----------------
Training Program 1
-----------------
area -> 25
>>

As a comparison you can write program above in command prompt matlab directly as follows :

>> length = 5;
>> width = 5;
>> area = length*width;
>> disp(['area ->' num2str(area)]);


It will be same if we write it in matlab editor :

length = 5;
width = 5;
area = length*width;
disp(['area ->' num2str(area)]);

So exclude ">>", you can write it on Matlab Editor and save it as matlab file.

Tips:
Makesure you don't give the name of variable or matlab file name same with default name which recognized by matlab. It is important to avoid overlapping naming.

1 comments:

Unknown said...

This blogs describes itself as a blog of Education and Training in India and works on latest technologies,I also doing Summer Internship Program at Noida in robospecies,Robospecies is a Robotics Training in India institute and I am very Confident about Robotics knowledge for more click here

Post a Comment