Introduction To Matlab Class 4 Instructors: Hristiyan (Chris) Kourtev and Xiaotao Su, PhD Double click the matlab icon When prompted click “Skip”

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Beginning Programming for Engineers
259 Lecture 17 Working with Data in MATLAB. Overview  In this lecture, we’ll look at some commands that are useful for working with data!  fzero  sum,
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Introduction to Matlab
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Matlab Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: 2D Graphics.
Matrix Manipulation and 2D Plotting
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Decision Analysis Tools in Excel
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
MATLAB GRAPHICS 2-D.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
Web Page Development Identify elements of a Web Page Start Notepad
1 Introduction to MatLab MatLab stands for Matrix Laboratory. As the name suggests most of the programming operations have as input or output a matrix.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/29/2003.
Matrix Mathematics in MATLAB and Excel
Introduction to Matlab Jianguo Wang CSSCR September 2009.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
INTRODUCTION TO MATLAB LAB# 01
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Scientific Computing Introduction to Matlab Programming.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to Matlab
Matlab Introduction  Getting Around Matlab  Matrix Operations  Drawing Graphs  Calculating Statistics  (How to read data)
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Matlab Class 6 Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS) and Chris Kourtev.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
An Introduction to Programming in Matlab Emily Blumenthal
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Matlab Class 8 Xiaotao Su, Ph.D. Visual Psychophysicist & IT Group Leader Rutgers Center for Cognitive Science (RuCCS) and Chris Kourtev.
L – Modeling and Simulating Social Systems with MATLAB Lecture 2 – Statistics and plotting © ETH Zürich | Giovanni Luca Ciampaglia,
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Created by Stacey Wilson
Computer Application in Engineering Design
Signals in Matlab Matlab as a name stands for Matrix Laboratory.
Introduction To Matlab Class 2
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Introduction To MATLAB
Introduction To Matlab Class 1
Introduction To Matlab Class 7
Reading a CSV file in R.
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files) Double click this icon
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
MATLAB How to use (using M-files)
Plotting Signals in MATLAB
Introduction to MATLAB
Presentation transcript:

Introduction To Matlab Class 4 Instructors: Hristiyan (Chris) Kourtev and Xiaotao Su, PhD Double click the matlab icon When prompted click “Skip”

Optional Presentation Title Unit Name Managing data To manage basic numerical data we use matrices our_data = [1, 4, 10.59, 12; 2, 9, 18.76, 5; 3, 7, 1.13, 2]; Trial 1 Trial 2 Trial 3 Response 1 Response 2 (perhaps the response time) Response 3 Trial Number

Optional Presentation Title Unit Name our_data = [1, 4, 10.59, 12; 2, 9, 18.76, 5; 3, 7, 1.13, 2]; To set the 4th row (4th trial) data: our_data(4, :) = [4, 7, 2.93, 3] –or we could our_data(5, 1) = 5; our_data(5, 2) = 1; our_data(5, 3) = 2.10; our_data(5, 4) = 9; To get this 4th row data –trial_data = our_data(4, :) : gets or sets all elements from row or column

Optional Presentation Title Unit Name %guessing_game.m %test to see if subject is psychic clear all; %settings num_trials = 5; highest_number = 3; %get info subject_name = input('What is your name?', 's'); for t = 1:num_trials %trial set up random_num = ceil(rand*highest_number); %perform experiment start_time = GetSecs; disp('I am thinking of a number between'); disp([' 1 and ', num2str(highest_number)]); response = input('What is it?'); stop_time = GetSecs; response_time = stop_time - start_time; is_correct = (response==random_num); if(is_correct) disp('Right!'); else disp(['Wrong! The correct answer was ',... num2str(random_num)]); end disp('Press any key to continue'); pause disp(' '); %record data guessing_game_data(t, :) =... [t, response_time, response,... random_num, is_correct ]; end

Optional Presentation Title Unit Name %guessing_game.m %test to see if subject is psychic clear all; %settings num_trials = 5; highest_number = 3; %get info subject_name = input('What is your name?', 's'); for t = 1:num_trials %trial set up random_num = ceil(rand*highest_number); %perform experiment start_time = GetSecs; disp('I am thinking of a number between'); disp([' 1 and ', num2str(highest_number)]); response = input('What is it?'); stop_time = GetSecs; response_time = stop_time - start_time; is_correct = (response==random_num); if(is_correct) disp('Right!'); else disp(['Wrong! The correct answer was ',... num2str(random_num)]); end disp('Press any key to continue'); pause disp(' '); %record data guessing_game_data(t, :) =... [t, response_time, response,... random_num, is_correct ]; end Task 1: Write this section of the program Hint: input without ‘s’ is a good way To get numeric responses from The subject

Optional Presentation Title Unit Name %guessing_game.m %test to see if subject is psychic clear all; %settings num_trials = 5; highest_number = 3; %get info subject_name = input('What is your name?', 's'); for t = 1:num_trials %trial set up random_num = ceil(rand*highest_number); %perform experiment start_time = GetSecs; disp('I am thinking of a number between'); disp([' 1 and ', num2str(highest_number)]); response = input('What is it?'); stop_time = GetSecs; response_time = stop_time - start_time; is_correct = (response==random_num); if(is_correct) disp('Right!'); else disp(['Wrong! The correct answer was ',... num2str(random_num)]); end disp('Press any key to continue'); pause disp(' '); %record data guessing_game_data(t, :) =... [t, response_time, response,... random_num, is_correct ]; end

Optional Presentation Title Unit Name %guessing_game.m %test to see if subject is psychic clear all; %settings num_trials = 5; highest_number = 3; %get info subject_name = input('What is your name?', 's'); for t = 1:num_trials %trial set up random_num = ceil(rand*highest_number); %perform experiment start_time = GetSecs; disp('I am thinking of a number between'); disp([' 1 and ', num2str(highest_number)]); response = input('What is it?'); stop_time = GetSecs; response_time = stop_time - start_time; is_correct = (response==random_num); if(is_correct) disp('Right!'); else disp(['Wrong! The correct answer was ',... num2str(random_num)]); end disp('Press any key to continue'); pause disp(' '); %record data guessing_game_data(t, :) =... [t, response_time, response,... random_num, is_correct ]; end

Optional Presentation Title Unit Name CSV format Stands for “Comma separated value” It is a simple text file for data storage Each data item is delimited (separated) by a comma Each data row is delimited by a return character

Optional Presentation Title Unit Name Notepad example Start->run notepad 1, 4, 9.3 1, 9, 100 4, 0, 12 Save as test.csv Double click -> opens in excel

Optional Presentation Title Unit Name csvwrite saves a 2d matrix as a csv file csvwrite(FILENAME, MATRIX_VAR) my_matrix = [3, 5; 1, 2]; csvwrite(‘my_data.csv’, my_matrix);

Optional Presentation Title Unit Name %guessing_game.m %test to see if subject is psychic clear all; %settings num_trials = 5; highest_number = 3; %get info subject_name = input('What is your name?', 's'); for t = 1:num_trials %trial set up random_num = ceil(rand*highest_number); %perform experiment start_time = GetSecs; disp('I am thinking of a number between'); disp([' 1 and ', num2str(highest_number)]); response = input('What is it?'); stop_time = GetSecs; response_time = stop_time - start_time; is_correct = (response==random_num); if(is_correct) disp('Right!'); else disp(['Wrong! The correct answer was ',... num2str(random_num)]); end disp('Press any key to continue'); pause disp(' '); %record data guessing_game_data(t, :) =... [t, response_time, response,... random_num, is_correct ]; end %data_storage csvwrite([subject_name, '.csv'], … guessing_game_data);

Optional Presentation Title Unit Name csvread clear all; my_matrix = csvread(‘my_data.csv’); can be used to load parameters at the beginning of a program can be used to load data to analyze through matlab

Optional Presentation Title Unit Name cell arrays this_is_a_matrix_and_a_vector = [5, 3, 9, 3] and_so_is_this = [‘hello’]; which_is_the_same_as = [‘h’, ‘e’, ‘l’, ‘l’, ‘o’];

Optional Presentation Title Unit Name cell arrays cell array provides a storage mechanism for dissimilar kinds of data they are like a matrix where each element is any other data type example_cell_array = {‘cat’, 3, [5, 9]; ‘zebra’, [10, 3; 9, 5], ‘dog’}; ‘cat’3 ‘zebra’‘dog’

Optional Presentation Title Unit Name a = example_cell_array{2, 3} example_cell_array{2, 1} = a example_cell_array{2, 2}(2, 1) ‘cat’3 ‘zebra’‘dog’

Optional Presentation Title Unit Name cell2csv Works just like csvwrite Will only work with “simple” cell arrays –no numeric vectors or matrices data = {‘trial number’, ‘time’, ‘color’, ‘response’; 1, 5.99, ‘blue’, 3; 2, 4, ‘green’, 2; 3, 55, ‘yellow’, 2} cell2csv(‘somefile.csv’, data); !Note: cell2csv is not a built in Matlab function. Download it here: _7/cell2csv.m _7/cell2csv.m

Optional Presentation Title Unit Name important note to add one data element to a cell array –data{5, 3} = 'yellow’ curly braces To add one row of data –data(5, :) = {4, 2.93, ‘yellow’, 4} parenthesis –data(trial+1, :) = {trial, time, color, response}

Optional Presentation Title Unit Name Creating a vector of numbers This is similar to the way you create an iteration for a “for” loop x = (0:20) ----> x = [0, 1, … 20] x = (0.1:0.1:1) ---> x = [0.1, 0.2, …, 1.0] x = (0:2:20) ----> x = [0, 2, 4, … 20] x = (0:2:20)’ ---> vertical vector like the previous one

Optional Presentation Title Unit Name discrete distributions and selecting segments you can use something like x=(0:20) to specify a discrete distribution of 21 different possibilities to select the first 6 elements you could say y = x(1:6) ---> y would be [0, 1 … 5] Or to select the last 4 elements y = x(end-3:end) ---> y would be [17, 18, 19, 20]

Optional Presentation Title Unit Name y = binopdf(x(1:6), 5,.8) used to generate a binomial distribution function the case in which one flips a weighted coin.8 probability of getting heads there are 6 possibilities (0 heads, 1 head… 5 heads y gives the probability of each of these outcomes This function requires the stats toolbox

Optional Presentation Title Unit Name Plotting Subplot will create a figure window for plotting subplot (2, 1, 2) will say we are going to create a (2 row, 1 column, …) figure. The last number specifies that we are currently going to write in the second element of this figure. plot(y) will create a graph on currently chosen section of the figure (specified by the third parameter in subplot)

Optional Presentation Title Unit Name setting up the plot xlim([1 5]) %sets the limits of the x axis bar(y) %will use a bar graph ylabel(‘Probability of n’) xlabel(‘N’) title(‘Discrete distributions should be plotted as histograms’)

Optional Presentation Title Unit Name more then one figure? figure %opens a new figure window All new subplots will go to the new figure subplot(2, 1, 1) bar(y) xlim([1 21]) %we want 21 possibilities

Optional Presentation Title Unit Name more then one graph on a plot hold on %tells matlab to keep the previous graph and draw a new one on top stairs(cumsum(y), ‘r’) –cumsum(y) <--- each value is the sum of previous values of y –‘r’ makes the graph line red –stairs will plot it as a staircase hold off % now any future graph additions will clear previous graphs on this plot legend(‘distribution’, ‘cumsum’)

Optional Presentation Title Unit Name ezplot Easy-to-use function plotter ezplot(fun) plots the expression fun(x) over the default domain -2pi < x < 2pi. This example plots the implicitly defined function x 2 - y 4 = 0 over the domain [-2pi, 2pi]: ezplot('x^2-y^4') You can specify a different domain by passing in a second argument to ezplot, in this case -6<x<6 and -2<y<1: eq='y - sin(x) + 1/2'; ezplot(eq,[-6,6,-2,1])

Optional Presentation Title Unit Name Solving Equations Using Matlab (symbolic toolbox) The present tutorial deals exclusively with numerical methods of solving algebraic and trigonometric equations, both single and several simultaneously, both linear and non-linear. Analytical solutions can be obtained using the methods described in the symbolic tutorial. When both symbolic and numerical methods work, sometimes one is simpler and sometimes the other.symbolic tutorial

Optional Presentation Title Unit Name Solving Equations Using Matlab (examples) “fzero” command - finds the value of x for f(x) = 0. e.g. For equation sin 2 (x) e -x/2 – 1 = 0 x = fzero('sin(x)^2*exp(-x/2)-1', -1) Using “solve” to solve linear and quadratic equations: e.g. For equation y = x 2 – 1, or y = 5x - 4 solve(‘x^2-1’); solve(‘5*x – 4’); And many more types of equations. Just read the tutorial and the help page for “solve”, “dsolve”, “fsolve”, “fzero”, etc.