{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

6_pdfsam_2 - Matlab workspace or Base workspace The...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
When a command of this form is executed, the expression is evaluated, producing a number that is assigned to the variable. The variable name and its value are displayed. If a variable name is not specified, Matlab will assign the result to the default variable, ans , as shown in previous examples. Example 2.1 Expressions with variables >> screws = 32 screws = 32 >> bolts = 18 bolts = 18 >> rivets = 40; >> items = screws + bolts + rivets items = 90 >> cost = screws * 0.12 + bolts * 0.18 + rivets * 0.08 cost = 10.2800 Variables: screws, bolts, rivets, items, cost Results displayed and stored by variable name Semicolon at the end of a line (as in the line >> rivets=40; ) tells Matlab to evaluate the line but not to display the results Matlab workspace: Variables created in the Command window are said to reside in the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Matlab workspace or Base workspace. The workspace retains the values of these variables, allowing them to be used in subsequent expressions. Thus, for the example above, we are able to compute the average cost per item by the following: >> average_cost = cost/items average_cost = 0.1142 Because average cost is two words and Matlab variable names must be one word, an underscore was used to create the single Matlab variable average_cost . If an expression contains variables, the value of the expression can be computed only if the values of the variables have been previously computed and still reside in the workspace. To compute the value of y = x + 5, you must Frst supply a value of x : 19...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online