matlab6 - Functions Scripts and Workspace scripts are just...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Functions
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Scripts and Workspace scripts are just a collection of commands, running a script is same as running the statements in command window. Your scripts and command window shares the same set of variables, also called the workspace.
Background image of page 2
Passing a variable to a script Command Window: >>x=2; >>script 2 >>x x = 5 script.m : disp(num2str(x)) x = 5;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Global Variables Variables in scripts and command window are shared, in other words, they are global. Global variables have been found to be problematic, since your program could erase a value needed by some other script, or the values you depend on might be changed by some other program. These side-effects are difficult to find In large systems, name clashes would be very common.
Background image of page 4
Passing Data to a Script Let’s say we have a script that sums the values in a vector : sum_vect.m : sum = 0; for x=1:length(v) sum = sum + v(x) end
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Passing Data to a Script We have another program where we are given three vectors: a,b, & c. We want to take the average of all elements in them. How can we make use of sum script?
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/29/2010 for the course CS 111 taught by Professor Stuff during the Fall '08 term at Bilkent University.

Page1 / 18

matlab6 - Functions Scripts and Workspace scripts are just...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online