Mathematics, Chalmers University of Technology and Göteborg University

#### Matlab exercise 3

(written by Kenneth Eriksson, modified by Stig Larsson)

Strings:

>> s=1+2

>> s='1+2'

>> eval(s)

>> f='2*x'

>> eval(f)

>> x=7

>> eval(f)

>> f(2)

>> f(3)

>> ['text1' 'text2']

>> ['text' 7]

>> ['text' num2str(7)]

>> help num2str

>> disp(['f(x)=' num2str(eval(f))])

>> help disp

>> whos

==============================

Elementary graphics:

>> x=0:.2:1

>> y=x.^2

>> plot(x,y)

>> plot(x,1-x/2)

>> plot(x,sin(10*x))

>> x=0:.01:1;

>> plot(x,sin(10*x))

>> xlabel('x')

>> ylabel('y')

>> xlabel('x_1'); ylabel('x_2')

>> title('My first plot')

>> hold on

>> plot(x,x.^2)

>> grid on

>> clf

>> subplot(211); plot(x,sin(10*x))

>> subplot(212); plot(x,x.^2)

>> get(gcf)

============================

Search priorities:

>> max(2,1)

>> max=[1 2 3;4 5 6]

>> max(2,1)

>> clear max

>> max(2,1)

>> hello

( I assume that your hello.m file is intact with the text disp('hi') )

>> hello=5;

>> hello

>> who

>> clear hello

>> hello

>> path

>> help path

>> dir

>> ls

>> help ls

>> help dir

>> help mkdir

>> mkdir m-files

>> help cd

>> cd m-files

>> dir

>> edit

( type disp('hi from hello in m-files') and save as hello.m )

>> hello

>> cd ..

>> hello

(the idea is that you will now get a 'hi' from your old hello.m file)

========================

Documentation:

>> help max

>> edit

(open the files hello.m and add info of its content/function, for example, as follows: % this file just replies 'hi')

>> help hello

=========================