1 / 7

Mastering Array Operations and Functions in MATLAB

Learn array operations, functions, data handling, and file imports in MATLAB. Explore exercises and examples on wages and data manipulation techniques.

serio
Download Presentation

Mastering Array Operations and Functions in MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Engr 6 Matlab Day 3Array Operations and Functions • Array Operations • Array Ops Exercises • Array Functions • Data: .mat files, • Wages Example • Import from Excel • HtNWt Example • Homework Hints Drop off homework on front table Pick up graded work – alphabetical by last name

  2. Array Operations • +-*/\ with a scalar, affects each array element A*3 • +- with two arrays, sizes match, element by element A+B • */\ with two arrays is matrix multiply (covered later) A*B • .* ./ .\ with two arrays, sizes match, el by el A./B

  3. Array Functions • In pairs, investigate a function on the function examples workbook page using doc. • Formulate 2 to 3 sentences that capture what the function does and the options the programmer has to use the function. • Share with the class.

  4. Data Files: .mat , Load and Save N:/Engineering/Engr6/Widgets.mat • Double click on .mat files to load data from the hard-drive into workspace variables. • Can also use load command or load() function • load Widgets.mat • load(‘Widgets.mat’) • Can save workspace variables to hard-drive. • save Payroll.matEarning Payroll • save(‘Payroll.mat’ , ‘Earnings’, ‘Payroll’)

  5. Importing Data from Excel • >> HtNWt = xlsread(‘Celebrity HtNWt.xlsx’) if the file is in the current directory • OR double click on excel file in current directory opens the Import Wizard adjust data types, variable names, selection range green check to import

  6. Homework Hints • Truncate large data outputs to save paper • Show the first few and last few elements • [1,2,3… 998, 999, 1000] • logspace is tricky • Use doc or help to see how it works • Double check your results • Display formats can be strange • Ans= 1.0e+003* 1 2 3 4 5 … • Must treat data as vectors or matrices • Must use descriptive variable names • Element by Element needs a dot .* • Check sizes to avoid syntax errors

  7. Bonus Challenge • A= rand(4,5); • [x,y]=sort(A); • Output = A([y(:,3)],:) What does each line of code do? What’s the final result of the code?

More Related