This is a Classroom License for instructional use only. Research and commercial use is prohibited. >> pwd ans = /Volumes/nfshome/schar/Documents/MATLAB >> pwd ans = /Volumes/nfshome/schar/Desktop >> cd matlab/ >> 3+4 ans = 7 >> a = [3 4 77; 2 1 8] a = 3 4 77 2 1 8 >> a(1, 2) ans = 4 >> help basic_script CS 150 class example This is a script. It runs a few statements comparing different ways of outputting values. >> basic_script display some text ans = a string without a semicolon a string without a semicolon another display a string with a semicolon >> x = 3+4 x = 7 >> x = 3+4; >> my_sqrt(16) ans = 4 >> guess_game Guess a number (1-10): 4 A bit too low... Guess a number (1-10): 7 A bit too low... Guess a number (1-10): 9 Got it! >> input('enter something') enter something44 ans = 44 >> input('enter something') enter something3+4 ans = 7 >> input('enter something') enter something[3 4; 6+6 9] ans = 3 4 12 9 >> input('enter something') enter somethingabc Error using input Undefined function or variable 'abc'. enter somethinga ans = 3 4 77 2 1 8 >> x = input('enter something') enter something x = [] >> help isempty isempty True for empty array. isempty(X) returns 1 if X is an empty array and 0 otherwise. An empty array has no elements, that is prod(size(X))==0. Other functions named isempty Reference page in Help browser doc isempty >> isempty(3) ans = 0 >> isempty([]) ans = 1 >> doc randi >> a a = 3 4 77 2 1 8 >> b = [1 0 10; 100 200 300] b = 1 0 10 100 200 300 >> size(a) ans = 2 3 >> x = size(a) x = 2 3 >> [rows, cols] = size(a) rows = 2 cols = 3 >> a' ans = 3 2 4 1 77 8 >> a a = 3 4 77 2 1 8 >> size(a') ans = 3 2 >> sum(a) ans = 5 5 85 >> sum(a') ans = 84 11 >> sum(a')' ans = 84 11 >> a a = 3 4 77 2 1 8 >> a+b ans = 4 4 87 102 201 308 >> a*b Error using * Inner matrix dimensions must agree. >> a .* b ans = 3 0 770 200 200 2400 >> disp(a) 3 4 77 2 1 8 >> disp(b) 1 0 10 100 200 300 >> a>b ans = 1 1 1 0 0 0 >> a>50 ans = 0 0 1 0 0 0 >> a>5 ans = 0 0 1 0 0 1 >> a a = 3 4 77 2 1 8 >> sum(a>5) ans = 0 0 2 >> sum(sum(a>5)) ans = 2 >> doc dlmread >> dlmread('data.txt') ans = 1 85 2 80 3 75 4 67 5 50 6 60 7 65 8 68 9 71 10 80 >> r = dlmread('data2.txt') r = 1 85 60 2 80 50 3 75 60 4 67 50 5 50 60 6 60 50 7 65 60 8 68 50 9 71 60 10 80 50 >> r = dlmread(data2.txt) Undefined variable "data2" or function "data2.txt". >> r(1, :) ans = 1 85 60 >> r(:, 3) ans = 60 50 60 50 60 50 60 50 60 50 >> r(1:2, 1:2) ans = 1 85 2 80 >> r(1:2, 2:) r(1:2, 2:) | Error: Unbalanced or unexpected parenthesis or bracket. >> r(1:2, 2:end) ans = 85 60 80 50 >> plot_file('data.txt') >> plot_file('data2.txt') >> a a = 3 4 77 2 1 8 >> b b = 1 0 10 100 200 300 >> a+b ans = 4 4 87 102 201 308 >> matrix_add(a, b) ans = 4 4 87 102 201 308 >> t = ones(5000); >> u = t+t; >> u = matrix_add(t, t); >> t = ones(50000); Requested 50000x50000 (18.6GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. >> t = ones(10000); >> u = t+t; % pretty fast >> u = matrix_add(t, t); % takes several seconds