├── .gitignore ├── LICENSE ├── README.md ├── assets ├── certificate.pdf └── certificate.png ├── week-2 ├── lesson_1_wrap_up.m ├── program1.m └── test.m ├── week-3 ├── assets │ ├── question-1.PNG │ ├── question-10-2.PNG │ ├── question-2.PNG │ ├── question-3.PNG │ ├── question-4.PNG │ ├── question-5.PNG │ ├── question-6-2.PNG │ ├── question-7.PNG │ ├── question-8.PNG │ └── question-9-2.PNG ├── colon_operators.m ├── lesson-2-wrap-up.md ├── matrix_arithmetic.m └── matrix_indexing.m ├── week-4 ├── corners.m ├── randRange.m ├── taxi_fare.m └── tri_area.m ├── week-5 ├── minimax.m ├── randInt.m ├── taking_input.m └── trio.m ├── week-6 ├── eligible.m ├── multiTable.m ├── persistent_variables.m ├── picker.m ├── under_age.m ├── valid_date.m └── valid_date_1.m ├── week-7 ├── freezing.m ├── halfsum.m ├── is_leap_year.m ├── max_sum.m └── next_prime.m ├── week-8 ├── caesar.m └── sparse2matrix.m └── week-9 ├── Distances.xlsx ├── Frankenstein-by-Shelley.txt ├── blur.m ├── char_counter.m ├── echo_gen.m ├── get_distance.m ├── lenna.png ├── saddle.m ├── simple.txt └── taking_file_input.m /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | out 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 anishLearnsToCode 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit 6 | persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction to Programming with MATLAB ~ Vanderbilt University 2 | 3 | [![course-list](https://img.shields.io/badge/also%20see-Other%20Coursera%20Courses-fe4523.svg)](https://github.com/anishLearnsToCode/course-list#coursera) 4 | ![problems-solved](https://img.shields.io/badge/Problems%20Solved-100%25-1abc9c.svg) 5 | 6 | 📹[My YouTube Channel](https://www.youtube.com/channel/UC6zEtIjpypm8gADSdHMP5vg) 7 | 8 | ## 📖 Overview 9 | - [Week 1: Course Pages](week-1-course-pages) 10 | - [Week 2: The MATLAB Environment](#week-2-the-matlab-environment) 11 | - [Week 3: Matrices and Operators](#week-3-matrices-and-operators) 12 | - [Week 4: Functions](#week-4-functions) 13 | - [Week 5: Programmer's Toolbox](#week-5-programmers-toolbox) 14 | - [Week 6: Selection](#week-6-selection) 15 | - [Week 7: Loops](#week-7-loops) 16 | - [Week 8: Data Types](#week-8-data-types) 17 | - [Week 9: File Input/Output](#week-9-file-inputoutput) 18 | - [Certificate](#-certificate) 19 | 20 | 21 | ## Week 1: Course Pages 22 | No Graded Assignment or Quiz 23 | 24 | ## Week 2: The MATLAB Environment 25 | ### Programming Assignments 26 | - [MATLAB as a Calculator](week-2/program1.m) 27 | - [Lesson 1 Wrap-Up](week-2/lesson_1_wrap_up.m) 28 | 29 | ## Week 3: Matrices and Operators 30 | ### Programming Assignments 31 | - [Assignment: Colon Operators](week-3/colon_operators.m) 32 | - [Assignment: Matrix Indexing](week-3/matrix_indexing.m) 33 | - [Assignment: Matrix Arithmetic](week-3/matrix_arithmetic.m) 34 | 35 | ### Quizzes 36 | - [Lesson 2 Wrap Up](week-3/lesson-2-wrap-up.md) 37 | 38 | ## Week 4: Functions 39 | ### Programming Assignments 40 | - [Assignment: A Simple Function](week-4/tri_area.m) 41 | - [Assignment: Multiple Outputs](week-4/corners.m) 42 | - [Assignment: Lesson 3 Wrap-Up](week-4/taxi_fare.m) 43 | 44 | ## Week 5: Programmer's Toolbox 45 | ### Programming Assignments 46 | - [Assignment: Built-In Functions](week-5/minimax.m) 47 | - [Assignment: Matrix Construction](week-5/trio.m) 48 | 49 | ## Week 6: Selection 50 | ### Programming Assignments 51 | - [Assignment: If-Statement Practice](week-6/picker.m) 52 | - [Assignment: More Practice](week-6/eligible.m) 53 | - [Assignment: nargin](week-6/under_age.m) 54 | - [Assignment: Lesson 5 Wrap-Up](week-6/valid_date.m) 55 | 56 | ## Week 7: Loops 57 | ### Programming Assignments 58 | - [Assignment: for-loop Practice](week-7/halfsum.m) 59 | - [Assignment: while-loop Practice](week-7/next_prime.m) 60 | - [Assignment: Logical Indexing](week-7/freezing.m) 61 | - [Lesson 6 Wrap-Up](week-7/max_sum.m) 62 | 63 | ## Week 8: Data Types 64 | ### Programming Assignments 65 | - [Assignment: Character Vectors](week-8/caesar.m) 66 | - [Assignment: Using Cell Arrays](week-8/sparse2matrix.m) 67 | 68 | ## Week 9: File Input/Output 69 | ### Programming Assignments 70 | - [Assignment: Excel Files](week-9/get_distance.m) 71 | - [Assignment: Text Files](week-9/char_counter.m) 72 | - [Assignment: Saddle Points](week-9/saddle.m) 73 | - [Assignment: Image Blur](week-9/blur.m) 74 | - [Assignment: Echo Generator](week-9/echo_gen.m) 75 | 76 | ## 🎓 [Certificate](http://coursera.org/verify/3S3AANA8JQTN) 77 | ![certificate](assets/certificate.png) 78 | -------------------------------------------------------------------------------- /assets/certificate.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/assets/certificate.pdf -------------------------------------------------------------------------------- /assets/certificate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/assets/certificate.png -------------------------------------------------------------------------------- /week-2/lesson_1_wrap_up.m: -------------------------------------------------------------------------------- 1 | time = 9.58 / 3600; 2 | distance = 0.1; 3 | hundred = distance / time; 4 | 5 | distance = 42.195; 6 | time = 2 + 1 / 60 + 39 / 3600; 7 | marathon = distance / time; 8 | -------------------------------------------------------------------------------- /week-2/program1.m: -------------------------------------------------------------------------------- 1 | principal = 1000; 2 | alpha = 0.1; 3 | debt = principal * (1 + alpha) ^ 2; 4 | disp(debt); 5 | -------------------------------------------------------------------------------- /week-2/test.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear; 3 | close all; 4 | 5 | plot([1, 2, 3], [3, 5, 10], 'rs'); 6 | -------------------------------------------------------------------------------- /week-3/assets/question-1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-1.PNG -------------------------------------------------------------------------------- /week-3/assets/question-10-2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-10-2.PNG -------------------------------------------------------------------------------- /week-3/assets/question-2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-2.PNG -------------------------------------------------------------------------------- /week-3/assets/question-3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-3.PNG -------------------------------------------------------------------------------- /week-3/assets/question-4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-4.PNG -------------------------------------------------------------------------------- /week-3/assets/question-5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-5.PNG -------------------------------------------------------------------------------- /week-3/assets/question-6-2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-6-2.PNG -------------------------------------------------------------------------------- /week-3/assets/question-7.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-7.PNG -------------------------------------------------------------------------------- /week-3/assets/question-8.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-8.PNG -------------------------------------------------------------------------------- /week-3/assets/question-9-2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-3/assets/question-9-2.PNG -------------------------------------------------------------------------------- /week-3/colon_operators.m: -------------------------------------------------------------------------------- 1 | odds = 1:2:100; 2 | evens = 100:-2:1; 3 | -------------------------------------------------------------------------------- /week-3/lesson-2-wrap-up.md: -------------------------------------------------------------------------------- 1 | Lesson 2 Wrap Up Quiz 2 | 3 | ![Question 1](assets/question-1.PNG) 4 | ![Question 2](assets/question-2.PNG) 5 | ![Question 3](assets/question-3.PNG) 6 | ![Question 4](assets/question-4.PNG) 7 | ![Question 5](assets/question-5.PNG) 8 | ![Question 6](assets/question-6-2.PNG) 9 | ![Question 7](assets/question-7.PNG) 10 | ![Question 8](assets/question-8.PNG) 11 | ![Question 9](assets/question-9-2.PNG) 12 | ![Question 10](assets/question-10-2.PNG) 13 | -------------------------------------------------------------------------------- /week-3/matrix_arithmetic.m: -------------------------------------------------------------------------------- 1 | A = [1:5; 6:10; 11:15; 16:20]; 2 | A1 = ones(1, size(A, 1)); 3 | B1 = ones(size(A, 2), 1); 4 | result = A1 * A * B1 ; 5 | -------------------------------------------------------------------------------- /week-3/matrix_indexing.m: -------------------------------------------------------------------------------- 1 | A = [1:5; 6:10; 11:15; 16:20]; 2 | v = A(:, 2); 3 | A(end, :) = 0; 4 | -------------------------------------------------------------------------------- /week-4/corners.m: -------------------------------------------------------------------------------- 1 | function [a, b, c, d] = corners(M) 2 | a = M(1, 1); 3 | b = M(1, end); 4 | c = M(end, 1); 5 | d = M(end, end) 6 | end 7 | -------------------------------------------------------------------------------- /week-4/randRange.m: -------------------------------------------------------------------------------- 1 | function [r, s] = randRange(rangeNumbers, dimension) 2 | r = rand(dimension); 3 | a = rangeNumbers(1); 4 | b = rangeNumbers(2); 5 | r = a + (b - a) * r; 6 | s = sumElements(r); 7 | myTest(); 8 | end 9 | 10 | function myTest() 11 | disp('hello world'); 12 | end 13 | 14 | function s = sumElements(M) 15 | s = sum(sum(M)); 16 | end -------------------------------------------------------------------------------- /week-4/taxi_fare.m: -------------------------------------------------------------------------------- 1 | function fare = taxi_fare(distance, time) 2 | fare = 5 + 2 * (ceil(distance) - 1) + 0.25 * ceil(time); 3 | end 4 | -------------------------------------------------------------------------------- /week-4/tri_area.m: -------------------------------------------------------------------------------- 1 | function a = tri_area(b, h) 2 | a = 0.5 * b * h; 3 | end 4 | -------------------------------------------------------------------------------- /week-5/minimax.m: -------------------------------------------------------------------------------- 1 | function [max_min_diff, total_max_min_diff] = minimax(M) 2 | max_rows = max(M'); 3 | min_rows = min(M'); 4 | max_min_diff = max_rows - min_rows; 5 | total_max_min_diff = max(max_rows) - min(min_rows); 6 | end 7 | -------------------------------------------------------------------------------- /week-5/randInt.m: -------------------------------------------------------------------------------- 1 | function [r, s] = randInt(rangeNums, dimensions) 2 | start = rangeNums(1); 3 | last = rangeNums(2); 4 | r = start + (last - start) * rand(dimensions); 5 | r = round(r); 6 | s = sum(sum(r)); 7 | end -------------------------------------------------------------------------------- /week-5/taking_input.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear; 3 | 4 | x = input('Enter input data : '); 5 | fprintf('text %.2f \n', x); 6 | -------------------------------------------------------------------------------- /week-5/trio.m: -------------------------------------------------------------------------------- 1 | function M = trio(n, m) 2 | M = ones(3 * n, m); 3 | M(n + 1 : 2 * n, :) = 2 * ones(n, m); 4 | M(2 * n + 1 : end, :) = 3 * ones(n, m); 5 | end 6 | -------------------------------------------------------------------------------- /week-6/eligible.m: -------------------------------------------------------------------------------- 1 | function admit = eligible(verbal, quant) 2 | admit = mean([verbal quant]) >= 92 && verbal > 88 && quant > 88; 3 | end 4 | -------------------------------------------------------------------------------- /week-6/multiTable.m: -------------------------------------------------------------------------------- 1 | function [table, s] = multiTable(n, m) 2 | if nargin == 1 3 | m = n; 4 | end 5 | 6 | table = (1 : n)' * (1 : m); 7 | 8 | if nargout == 2 9 | s = sum(sum(table)); 10 | end 11 | end -------------------------------------------------------------------------------- /week-6/persistent_variables.m: -------------------------------------------------------------------------------- 1 | function count = persistent_variables(n) 2 | if nargin == 0 3 | n = 1; 4 | end 5 | 6 | persistent acc; 7 | if isempty(acc) 8 | acc = 1; 9 | else 10 | acc = acc + n; 11 | end 12 | count = acc; 13 | end 14 | -------------------------------------------------------------------------------- /week-6/picker.m: -------------------------------------------------------------------------------- 1 | function output = picker(condition, input1, input2) 2 | if condition 3 | output = input1; 4 | else 5 | output = input2; 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /week-6/under_age.m: -------------------------------------------------------------------------------- 1 | function too_young = under_age(age, limit) 2 | if nargin == 1 3 | limit = 21; 4 | end 5 | too_young = age < limit; 6 | end 7 | -------------------------------------------------------------------------------- /week-6/valid_date.m: -------------------------------------------------------------------------------- 1 | function valid = valid_date(y,m,d) 2 | if nargin == 3 3 | if ~isscalar(y) || y < 1 || y ~= fix(y) 4 | valid = false; 5 | return 6 | elseif ~isscalar(m) || m < 1 || m ~= fix(m) 7 | valid = false; 8 | return 9 | elseif ~isscalar(d) || d < 1 || d ~= fix(d) 10 | valid = false; 11 | return 12 | end 13 | end 14 | a=y/4;b=y/400;c=y/100; 15 | M1 = [1 3 5 7 8 10 12]; 16 | M2 = [4,6,9,11]; 17 | F1 = (1:29); 18 | F2 = (1:28); 19 | D1 = (1:31); 20 | D2=(1:30); 21 | if a ~= fix(a) || (b ~= fix(b) && c == fix(c)) 22 | if ismember(m,M1) && ismember(d,D1) 23 | valid = true; 24 | elseif ismember(m,M2) && ismember(d,D2) 25 | valid = true; 26 | elseif m==2 && ismember(d,F2) 27 | valid = true; 28 | else 29 | valid = false; 30 | end 31 | elseif a == fix(a) || b == fix(b) 32 | if ismember(m,M1) && ismember(d,D1) 33 | valid = true; 34 | elseif ismember(m,M2) && ismember(d,D2) 35 | valid = true; 36 | elseif m==2 && ismember(d,F1) 37 | valid = true; 38 | else 39 | valid = false; 40 | end 41 | end 42 | end -------------------------------------------------------------------------------- /week-6/valid_date_1.m: -------------------------------------------------------------------------------- 1 | function predicate = valid_date(year, month, day) 2 | predicate = is_positive_integer(year) ... 3 | && is_positive_integer(month) ... 4 | && is_positive_integer(day) ... 5 | && 1 <= month && month <= 12; 6 | predicate = predicate && (1 <= day && day <= max_date(month, year)); 7 | end 8 | 9 | function m = max_date(month, year) 10 | leap = is_leap_year(year); 11 | if month == 1 || month == 3 || month == 5 || month == 7 ... 12 | || month == 8 || month == 10 || month == 12 13 | m = 31; 14 | elseif month == 2 15 | if leap 16 | m = 29; 17 | else 18 | m = 28; 19 | end 20 | elseif month == 2 || month == 4 || month == 6 || month == 9 || ... 21 | month == 11 22 | m = 30; 23 | else 24 | m = -1; 25 | end 26 | end 27 | 28 | function predicate = is_leap_year(year) 29 | if year % 4 == 0 30 | if year % 100 == 0 31 | if year % 400 == 0 32 | predicate = 1; 33 | else 34 | predicate = 0; 35 | end 36 | else 37 | predicate = 1; 38 | end 39 | else 40 | predicate = 0; 41 | end 42 | end 43 | 44 | function predicate = is_positive_integer(val) 45 | predicate = val > 0 && val == floor(val); 46 | end 47 | -------------------------------------------------------------------------------- /week-7/freezing.m: -------------------------------------------------------------------------------- 1 | function count = freezing(temperatures) 2 | count = sum(temperatures < 32); 3 | end 4 | -------------------------------------------------------------------------------- /week-7/halfsum.m: -------------------------------------------------------------------------------- 1 | function s = halfsum(M) 2 | [n, m] = size(M); 3 | s = 0; 4 | for row = 1:n 5 | for column = row:m 6 | s = s + M(row, column); 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /week-7/is_leap_year.m: -------------------------------------------------------------------------------- 1 | function p = is_leap_year(year) 2 | if mod(year, 4) == 0 3 | if mod(year, 100) == 0 4 | if mod(year, 400) == 0 5 | p = true; 6 | else 7 | p = false; 8 | end 9 | else 10 | p = true; 11 | end 12 | else 13 | p = false; 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /week-7/max_sum.m: -------------------------------------------------------------------------------- 1 | function [summa, index] = max_sum(v, n) 2 | [~, len] = size(v); 3 | summa = -inf; 4 | if n > len 5 | summa = 0; 6 | end 7 | index = -1; 8 | for i = 1:(len - n + 1) 9 | s = sum(v(i : i + n - 1)); 10 | if s > summa 11 | summa = s; 12 | index = i; 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /week-7/next_prime.m: -------------------------------------------------------------------------------- 1 | function number = next_prime(number) 2 | while ~isprime(number + 1) 3 | number = number + 1; 4 | end 5 | number = number + 1; 6 | end 7 | -------------------------------------------------------------------------------- /week-8/caesar.m: -------------------------------------------------------------------------------- 1 | function coded = caesar(sequence, shift) 2 | sequence = double(sequence); 3 | sequence = sequence + shift; 4 | coded = char(loop(32, 126, sequence)); 5 | end 6 | 7 | function val = loop(start, stop, val) 8 | r = stop - start + 1; 9 | val = mod(val - start + r, r) + start; 10 | end 11 | -------------------------------------------------------------------------------- /week-8/sparse2matrix.m: -------------------------------------------------------------------------------- 1 | function matrix = sparse2matrix(sparse_matrix) 2 | dimensions = cell2mat(sparse_matrix(1)); 3 | n = dimensions(1); m = dimensions(2); 4 | default = cell2mat(sparse_matrix(2)); 5 | matrix = default * ones(n, m); 6 | 7 | [~, len] = size(sparse_matrix); 8 | for i = 3:len 9 | element = cell2mat(sparse_matrix(i)); 10 | matrix(element(1), element(2)) = element(3); 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /week-9/Distances.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-9/Distances.xlsx -------------------------------------------------------------------------------- /week-9/blur.m: -------------------------------------------------------------------------------- 1 | function [output] = blur(A, w) 2 | [rows, columns] = size(A); 3 | B = nan(size(A) + 2 * w); 4 | B(w + 1 : end - w, w + 1 : end - w) = A; 5 | output = 0 * A; 6 | 7 | for i = w + 1 : rows + w 8 | for j = w + 1 : columns + w 9 | tmp = B(i - w : i + w, j - w : j + w); 10 | output(i - w, j - w) = mean(tmp(~isnan(tmp))); 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /week-9/char_counter.m: -------------------------------------------------------------------------------- 1 | function charnum = char_counter(file_name, character) 2 | file = fopen(file_name, 'rt'); 3 | if file < 0 || ~ischar(character) 4 | charnum = -1; 5 | return; 6 | end 7 | 8 | charnum = 0; 9 | line = fgets(file); 10 | while ischar(line) 11 | charnum = charnum + frequency(line, character); 12 | line = fgets(file); 13 | end 14 | end 15 | 16 | function count = frequency(line, character) 17 | count = sum(line == character); 18 | end 19 | -------------------------------------------------------------------------------- /week-9/echo_gen.m: -------------------------------------------------------------------------------- 1 | function output = echo_gen(in,fs,delay,gain) 2 | samples = round(fs * delay) ; 3 | ds = floor(samples); 4 | signal = zeros(length(in) + ds, 1); 5 | signal(1:length(in)) = in; 6 | echo_signal = zeros(length(in) + ds, 1); 7 | echo_signal(ds + (1:length(in*gain))) = in * gain; 8 | output = signal + echo_signal; 9 | p = max(abs(output)); 10 | if p > 1 11 | output = output ./ p; 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /week-9/get_distance.m: -------------------------------------------------------------------------------- 1 | function distance = get_distance(x,y) 2 | persistent raw; 3 | if isempty(raw) 4 | [~, ~, raw] = xlsread('Distances.xlsx'); 5 | end 6 | 7 | state1_index = state2index(raw, x); 8 | state2_index = state2index(raw, y); 9 | 10 | if state1_index > 1 && state2_index > 1 11 | distance = cell2mat(raw(state1_index, state2_index)); 12 | else 13 | distance = -1; 14 | end 15 | end 16 | 17 | function index = state2index(raw, state) 18 | [~, states] = size(raw); 19 | index = -1; 20 | for i = 2:states 21 | if strcmp(cell2mat(raw(1, i)), state) 22 | index = i; 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /week-9/lenna.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishLearnsToCode/introduction-to-programming-with-matlab/4eb0dfab3f41b8a20d890e8d01a9e9b7463de410/week-9/lenna.png -------------------------------------------------------------------------------- /week-9/saddle.m: -------------------------------------------------------------------------------- 1 | function indices = saddle(M) 2 | indices = zeros(0, 2); 3 | [rows, columns] = size(M); 4 | for row = 1:rows 5 | for column = 1 : columns 6 | point = M(row, column); 7 | if isGreaterThan(point, M(row, :)) && isSmallerThan(point, M(:, column)) 8 | indices(end + 1, :) = [row, column]; %#ok 9 | end 10 | end 11 | end 12 | end 13 | 14 | function predicate = isGreaterThan(point, vector) 15 | predicate = sum(point >= vector) == length(vector); 16 | end 17 | 18 | function predicate = isSmallerThan(point, vector) 19 | predicate = sum(point <= vector) == length(vector); 20 | end 21 | -------------------------------------------------------------------------------- /week-9/simple.txt: -------------------------------------------------------------------------------- 1 | This file should have exactly three a-s... -------------------------------------------------------------------------------- /week-9/taking_file_input.m: -------------------------------------------------------------------------------- 1 | function taking_file_input() 2 | 3 | end --------------------------------------------------------------------------------