Wednesday, November 17, 2010

0

MATLAB Program to Add 2 Numbers.

  • Wednesday, November 17, 2010
  • tech
  • Share
  • Lets Write a simple program to add two Programs
    As i had already discussed you can either execute program in the Command Window or save a program as .m file.
    1) Executing a program in a Command Window

    Just select the Command Window and write the necesary codes as shown below


    The figure shows how to add 2 numbers.
    Here i have used two variables x and y
    just write in the command window x='any value say 2' and y='say2'
    then write x+y and press enter.
    You wil get Result 4 in the command window as shown above
    Simple Huh!
    But for larger programs it is neccessary to save the program.


    Program to add two numbers using text editor

    Select Text Editor by using the Following Step


    Select file menu


    >select New


    >select .m file


    >type the program name and save the file and type the program code


    NOTE:We can write comments between the codes using the % symbol.just type % and write the codes


    Here Goes the Program


    clc; %clear command window
    x=input(' x='); %accept tha value of x
    y=input(' y='); %accept tha value of y
    z=x+y;
    disp('z='); %display function inbuilt in matlab to display a string
    disp(z); %display the value of z




    0 Responses to “MATLAB Program to Add 2 Numbers.”

    Post a Comment