├── 3dplot.m ├── Algebra.m ├── Anonymous.m ├── CONTRIBUTING.md ├── FaceDetection01.m ├── GlobalVariables.m ├── Lagrange.m ├── Multiple Functions on the Same Graph.m ├── Nested Functions ├── Nueral_Network.m ├── Private.m ├── RGBcomponents.m ├── Readme.md ├── adjoint.m ├── arraytomeshgrid.m ├── cat.m ├── clc.m ├── createChessboard.m ├── diary.m ├── diff.m ├── exist.m ├── extremadetection.m ├── eye.m ├── figure.m ├── find.m ├── format short e.m ├── fplot.m ├── fprintf.m ├── fsurf.m ├── grid.m ├── gtext.m ├── heatmap.m ├── hold.py ├── holdon.m ├── input.m ├── inverse.m ├── iscell.m ├── l&c_capacitance.m ├── legend.m ├── load.m ├── lookfor.m ├── matri.m ├── max.m ├── max_min_plot.m ├── meshgrid.m ├── mfiles.m ├── min.m ├── mymax.py ├── one.m ├── plot.m ├── plot_examples.m ├── pole_zero.m ├── prod.m ├── pwd.m ├── readtable.m ├── reshape.m ├── save.m ├── scattertosurface.m ├── semilogx.m ├── semilogy.m ├── short.m ├── size.m ├── stairs.m ├── stem.m ├── subplot.m ├── sum.m ├── switch.m ├── text.m ├── texture_based_segmentation.m ├── title.m ├── transpose.m ├── type.m ├── whos.m ├── xlabel.m └── ylabel.m /3dplot.m: -------------------------------------------------------------------------------- 1 | % Generate 3D plots in MATLAB. 2 | % Define x,y,z in parametric form (t) 3 | 4 | 5 | t = 0:pi/500:pi; 6 | xt1 = sin(t).*cos(10*t); 7 | yt1 = sin(t).*sin(10*t); 8 | zt1 = cos(t); 9 | 10 | xt2 = sin(t).*cos(12*t); 11 | yt2 = sin(t).*sin(12*t); 12 | zt2 = cos(t); 13 | 14 | plot3(xt1,yt1,zt1,xt2,yt2,zt2) 15 | -------------------------------------------------------------------------------- /Algebra.m: -------------------------------------------------------------------------------- 1 | y = solve('x-5 = 0') 2 | -------------------------------------------------------------------------------- /Anonymous.m: -------------------------------------------------------------------------------- 1 | power = @(x, n) x.^n; 2 | result1 = power(7, 3) 3 | result2 = power(49, 0.5) 4 | result3 = power(10, -10) 5 | result4 = power (4.5, 1.5) 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Welcome to open source project for MATLAB beginner 2 | 3 | Please go through the following step-by-step process to contribute to this project 4 | 5 | This is a MATLAB function examples project here we need to follow these steps 6 | 7 | step1: Give a star ⭐ to this project (optional) 8 | 9 | step2: Click on the fork button on the top right and wait a few seconds to complete the forking of this project 10 | 11 | step3: Click on add new file button and select create new file or upload file option (basically your .m file or notepad file .txt) 12 | 13 | step4: Give a suitable name for your file and a complete and correct Matlab example 14 | 15 | step5: Commit your file 16 | 17 | step6: Click the contribute button and click on create pull request option and click on create pull request and finally click on the commit 18 | 19 | Congratulation ! 😋 20 | 21 | Note: Please do not submit the same example that is already available and use different names for your file too. 👌 22 | -------------------------------------------------------------------------------- /FaceDetection01.m: -------------------------------------------------------------------------------- 1 | 2 | image_input = imread('Data4.jpeg'); 3 | [width,height] = size(image_input); 4 | 5 | if width>320 6 | image_input = imresize(image_input,[320 NaN]); 7 | end 8 | 9 | % Create a cascade detector object. 10 | faceDetector = vision.CascadeObjectDetector(); 11 | 12 | %finding the bounding box that encloses the face on video frame 13 | face_Location = step(faceDetector,image_input); 14 | 15 | % Draw the returned bounding box around the detected face. 16 | image_input= insertShape(image_input, 'Rectangle', face_Location); 17 | figure; 18 | imshow(image_input); 19 | title('Face Detection'); -------------------------------------------------------------------------------- /GlobalVariables.m: -------------------------------------------------------------------------------- 1 | global TOTAL; 2 | TOTAL = 10; 3 | n = [34, 45, 25, 45, 33, 19, 40, 34, 38, 42]; 4 | av = average(n) 5 | -------------------------------------------------------------------------------- /Lagrange.m: -------------------------------------------------------------------------------- 1 | % Lagrange Interpolation MATLAB Program 2 | function [P,R,S] = lagrangepoly(X,Y,XX) 3 | X = [1 2 3 4 5 6 7 8]; % inputting the values of given x 4 | Y = [0 1 0 1 0 1 0 1]; % inputting the values of given y 5 | %[P,R,S] = lagrangepoly(X,Y); 6 | xx = 0.5 : 0.01 : 8.5; 7 | %plot(xx,polyval(P,xx),X,Y,'or',R,S,'.b',xx,spline(X,Y,xx),'--g') 8 | %grid 9 | %axis([0.5 8.5 -5 5]) 10 | if size(X,1) > 1; X = X'; end % checking for parameters 11 | if size(Y,1) > 1; Y = Y'; end 12 | if size(X,1) > 1 || size(Y,1) > 1 || size(X,2) ~= size(Y,2) 13 | error('both inputs must be equal-length vectors') % displaying error 14 | end % end of scope of if 15 | N = length(X); 16 | pvals = zeros(N,N); 17 | % for evaluating the polynomial weights for each order 18 | for i = 1:N 19 | % the polynomial with roots may be values of X other than this one 20 | pp = poly(X( (1:N) ~= i)); 21 | pvals(i,:) = pp ./ polyval(pp, X(i)); 22 | end 23 | P = Y*pvals; 24 | if nargin==3 25 | YY = polyval(P,XX); % output is YY with given XX 26 | P = YY; % assigning to output 27 | end 28 | % end of scope of if 29 | if nargout > 1 % checking for conndtions 30 | R = roots( ((N-1):-1:1) .* P(1:(N-1)) ); 31 | if nargout > 2 32 | % the evalustion of acual value at the poins of zero derivative 33 | S = polyval(P,R); 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /Multiple Functions on the Same Graph.m: -------------------------------------------------------------------------------- 1 | x = [0 : 0.01: 10]; 2 | y = sin(x); 3 | g = cos(x); 4 | plot(x, y, x, g, '.-'), legend('Sin(x)', 'Cos(x)') 5 | -------------------------------------------------------------------------------- /Nested Functions: -------------------------------------------------------------------------------- 1 | function [x1,x2] = quadratic2(a,b,c) 2 | function disc % nested function 3 | d = sqrt(b^2 - 4*a*c); 4 | end % end of function disc 5 | 6 | disc; 7 | x1 = (-b + d) / (2*a); 8 | x2 = (-b - d) / (2*a); 9 | end % end of function quadratic2 10 | -------------------------------------------------------------------------------- /Nueral_Network.m: -------------------------------------------------------------------------------- 1 | data = thingSpeakRead(12397,'Fields',[2 3 4 6],'DateRange',[datetime('January 7, 2018'),datetime('January 9, 2018')],... 2 | 'outputFormat','table'); 3 | inputs = [data.Humidity'; data.TemperatureF'; data.PressureHg'; data.WindSpeedmph']; 4 | tempC = (5/9)*(data.TemperatureF-32); 5 | b = 17.62; 6 | c = 243.5; 7 | gamma = log(data.Humidity/100) + b*tempC ./ (c+tempC); 8 | dewPointC = c*gamma ./ (b-gamma); 9 | dewPointF = (dewPointC*1.8) + 32; 10 | targets = dewPointF'; 11 | net = feedforwardnet(10); 12 | [net,tr] = train(net,inputs,targets); 13 | output = net(inputs(:,5)) 14 | -------------------------------------------------------------------------------- /Private.m: -------------------------------------------------------------------------------- 1 | function dis = disc(a,b,c) 2 | %function calculates the discriminant 3 | dis = sqrt(b^2 - 4*a*c); 4 | end % end of sub-function 5 | -------------------------------------------------------------------------------- /RGBcomponents.m: -------------------------------------------------------------------------------- 1 | % Generate RGB components of the image using MATLAB. 2 | % Read the image 3 | image = imread('peppers.png'); 4 | 5 | % Split the image into its RGB components 6 | red = image(:, :, 1); 7 | green = image(:, :, 2); 8 | blue = image(:, :, 3); 9 | 10 | % Display the RGB components 11 | subplot(1, 3, 1); 12 | imshow(red); 13 | title('Red Channel'); 14 | 15 | subplot(1, 3, 2); 16 | imshow(green); 17 | title('Green Channel'); 18 | 19 | subplot(1, 3, 3); 20 | imshow(blue); 21 | title('Blue Channel'); 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Learn to Code with MATLAB 2 | Let's learn how to work with variables, functions, vectors and many more inbuilt commands. 3 | ![image](https://user-images.githubusercontent.com/61034696/190884326-66dcec66-26a7-41b9-b6ce-5779af0ed1de.png) 4 | 5 | Let's write various commands that illustrate the use of inbuilt as well as defined function codes with an example 6 | How to get your Pull request merged? 7 | step1: login and start the online MatLab editor screen at https://matlab.mathworks.com/ or open your MatLab on your machine. 8 | ![image](https://user-images.githubusercontent.com/61034696/190884486-77be5b97-1f86-4331-80bd-0fcb67aa761a.png) 9 | Step2: write any simple example that illustrates the use of any basic commands. Run to make sure the code is correct 10 | For example: plot command 11 | ![image](https://user-images.githubusercontent.com/61034696/190884774-5669db15-e76d-4aaa-96bd-a3ba572a0ed8.png) 12 | 13 | step 3: copy the code into notepad and upload it here or directly upload MatLab (plot.m) file. 14 | For more look CONTRIBUTING.md file instruction 15 | 16 | Here are some hints 17 | ![matlab-basic-functions-reference-1](https://user-images.githubusercontent.com/61034696/193260818-ea625af7-c1bf-4404-834c-2ab1b6341129.jpg) 18 | ![matlab-basic-functions-reference-2](https://user-images.githubusercontent.com/61034696/193260824-2a636011-2d8d-4d60-bcc4-9aa1b80f96a0.jpg) 19 | ![matlab-basic-functions-reference-3](https://user-images.githubusercontent.com/61034696/193260828-c2c38ae3-93af-41e1-aa3b-f111aa4d761a.jpg) 20 | ![matlab-basic-functions-reference-4](https://user-images.githubusercontent.com/61034696/193260836-143d9f43-51c9-40ec-80e8-7391ed3d03b1.jpg) 21 | -------------------------------------------------------------------------------- /adjoint.m: -------------------------------------------------------------------------------- 1 | %find adjoint of A [2 3 5; 1 7 2; 8 3 4] by using inv() and det() 2 | %make sure that the square matrix is non singular 3 | A=[2 3 5; 1 7 2; 8 3 4]; 4 | A_adj=inv(A).*det(A); 5 | disp(A_adj); 6 | -------------------------------------------------------------------------------- /arraytomeshgrid.m: -------------------------------------------------------------------------------- 1 | load seamount 2 | step_size = 0.01; 3 | [xq,yq] = meshgrid(min(x)-1:step_size:max(x)+1, min(y)-1:step_size:max(y)+1); 4 | zq = griddata(x,y,z,xq,yq); 5 | surf(xq,yq,zq) 6 | -------------------------------------------------------------------------------- /cat.m: -------------------------------------------------------------------------------- 1 | A = ones(3) 2 | B = zeros(3) 3 | C1 = cat(1,A,B) 4 | -------------------------------------------------------------------------------- /clc.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | $Clears command window. 4 | -------------------------------------------------------------------------------- /createChessboard.m: -------------------------------------------------------------------------------- 1 | function createChessboard() 2 | % Input: 3 | rows = 8; % No. of rows in the board 4 | cols = 8; % No. of columns in the board 5 | squareSize = 100; % Size of each square in pixels 6 | 7 | % Create the chessboard frame 8 | chessboard = zeros(cols*squareSize, rows*squareSize); 9 | 10 | % Fill the chessboard with alternating white and black squares pattern 11 | for i = 1:rows 12 | for j = 1:cols 13 | if mod(i+j, 2) == 0 14 | chessboard((i-1)*squareSize+1:i*squareSize, (j-1)*squareSize+1:j*squareSize) = 255; 15 | end 16 | end 17 | end 18 | 19 | % Display the chessboard pattern 20 | imshow(chessboard); 21 | end 22 | -------------------------------------------------------------------------------- /diary.m: -------------------------------------------------------------------------------- 1 | diary myDiaryFile 2 | -------------------------------------------------------------------------------- /diff.m: -------------------------------------------------------------------------------- 1 | syms t 2 | f = 3*t^2 + 2*t^(-2); 3 | diff(f) 4 | -------------------------------------------------------------------------------- /exist.m: -------------------------------------------------------------------------------- 1 | testresults = magic(5); 2 | exist testresults 3 | -------------------------------------------------------------------------------- /extremadetection.m: -------------------------------------------------------------------------------- 1 | [X,Y,Z] = peaks(25); 2 | CO(:,:,1) = zeros(25); % red 3 | CO(:,:,2) = ones(25).*linspace(0.5,0.8,25); % green 4 | CO(:,:,3) = ones(25).*linspace(0,1.2,25); % blue 5 | surf(X,Y,Z,CO) 6 | hold on 7 | 8 | % Detect Minima 9 | ix = find(imregionalmin(Z)); 10 | plot3(X(ix),Y(ix),Z(ix),'r*','MarkerSize',24) 11 | hold on 12 | 13 | % Detect Maxima 14 | ix = find(imregionalmax(Z)); 15 | plot3(X(ix),Y(ix),Z(ix),'b*','MarkerSize',24) -------------------------------------------------------------------------------- /eye.m: -------------------------------------------------------------------------------- 1 | I = eye(4) -------------------------------------------------------------------------------- /figure.m: -------------------------------------------------------------------------------- 1 | f1 = figure; 2 | f2 = figure; 3 | plot([1 2 3],[2 4 6]); 4 | -------------------------------------------------------------------------------- /find.m: -------------------------------------------------------------------------------- 1 | X = [1 0 2; 0 1 1; 0 0 4] 2 | k = find(X) 3 | -------------------------------------------------------------------------------- /format short e.m: -------------------------------------------------------------------------------- 1 | fmt = format("shortG"); 2 | format(fmt) 3 | -------------------------------------------------------------------------------- /fplot.m: -------------------------------------------------------------------------------- 1 | xt = @(t) cos(3*t); 2 | yt = @(t) sin(2*t); 3 | fplot(xt,yt) 4 | -------------------------------------------------------------------------------- /fprintf.m: -------------------------------------------------------------------------------- 1 | %simple multiplication program demonstrating usage of fprintf() until 2 decimal places 2 | a = 9.81; 3 | b = 50; 4 | m=a*b; 5 | fprintf('The result of a*b is: %.2f',m) 6 | -------------------------------------------------------------------------------- /fsurf.m: -------------------------------------------------------------------------------- 1 | %3D surface plot of wave function 2 | k=1; 3 | E0=5; 4 | t=pi/4; 5 | E=@(x,y) E0.*(cos(k.*cos(t).*x+k.*sin(t).*y)); 6 | fsurf(E); 7 | -------------------------------------------------------------------------------- /grid.m: -------------------------------------------------------------------------------- 1 | x = linspace(0,10); 2 | y = sin(x); 3 | plot(x,y) 4 | grid on 5 | -------------------------------------------------------------------------------- /gtext.m: -------------------------------------------------------------------------------- 1 | plot(1:10) 2 | gtext('My Plot') 3 | -------------------------------------------------------------------------------- /heatmap.m: -------------------------------------------------------------------------------- 1 | load patients 2 | tbl = table(LastName,Age,Gender,SelfAssessedHealthStatus,... 3 | Smoker,Weight,Location); 4 | 5 | h = heatmap(tbl,'Smoker','SelfAssessedHealthStatus',... 6 | 'ColorVariable','Age'); -------------------------------------------------------------------------------- /hold.py: -------------------------------------------------------------------------------- 1 | x = linspace(-pi,pi); 2 | y1 = sin(x); 3 | plot(x,y1) 4 | 5 | hold on 6 | y2 = cos(x); 7 | plot(x,y2) 8 | hold off 9 | -------------------------------------------------------------------------------- /holdon.m: -------------------------------------------------------------------------------- 1 | %hold on command in matlab comes in handy while plotting 2 or more functions on the same plot as shown 2 | r=linspace(-2,10); 3 | k=1; 4 | n1=0.5*k.*r.^2+(1/6*0.001*r.^3); 5 | n2=0.5*k.*r.^2+(1/6*0.01*r.^3); 6 | n3=0.5*k.*r.^2+(1/6*0.05*r.^3); 7 | plot(r,n1); 8 | hold on 9 | plot(r,n2); 10 | hold on 11 | plot(r,n3); 12 | -------------------------------------------------------------------------------- /input.m: -------------------------------------------------------------------------------- 1 | %program demonstrating usage of input() to read the data from user 2 | x=input('Enter number 1: '); 3 | y=input('Enter number 2: '); 4 | m=x*y; 5 | fprintf('Multiplication of a and b is: %.2f',m); 6 | -------------------------------------------------------------------------------- /inverse.m: -------------------------------------------------------------------------------- 1 | %find inverse of a matrix A [2 3 5; 1 7 2; 8 3 4] 2 | A=[2 3 5; 1 7 2; 8 3 4]; 3 | A_inv=inv(A); 4 | disp(A_inv); 5 | -------------------------------------------------------------------------------- /iscell.m: -------------------------------------------------------------------------------- 1 | A = {1,2,3; 2 | 'text',rand(5,10,2),{11; 22; 33}} 3 | tf = iscell(A) 4 | -------------------------------------------------------------------------------- /l&c_capacitance.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | %DSP LAB 5 | %Experiment 6 6 | %QUestion 1 : FIR Low Pass filter 7 | 8 | t_w = 500/10000; 9 | N = floor(4.32/t_w); 10 | M = floor((N-1)/2); 11 | n = -M:M; 12 | beta = 6.76; 13 | w_n = inot(beta*((1-((2.*n/(N-1)).^2)).^0.5))./inot(beta); 14 | figure() 15 | plot(n,w_n) 16 | fc =1200/10000; 17 | h_d_n = (-2*fc*sin(n*2*pi*fc))./(n*2*pi*fc); 18 | h_d_n(round(N/2)) =1 - 2*fc; 19 | figure() 20 | stem(n,h_d_n) 21 | 22 | h_n = w_n.*h_d_n; 23 | 24 | figure() 25 | stem(n,h_n); 26 | 27 | ff = -pi:0.00001:pi; 28 | 29 | 30 | for q = 1:length(ff) 31 | w = ff(q); 32 | temp = h_n.*exp(-1i*w.*n); 33 | h(q) = sum(temp); 34 | 35 | end 36 | figure() 37 | plot(ff,abs(h)) 38 | 39 | figure() 40 | plot(ff,angle(h)) 41 | 42 | function out = inot(x) 43 | out = zeros(1,length(x)); 44 | for i=0:50 45 | out = out + 1*((0.25*(x.^2)).^i)./(factorial(i)^2); 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /legend.m: -------------------------------------------------------------------------------- 1 | x = linspace(0,pi); 2 | y1 = cos(x); 3 | plot(x,y1) 4 | 5 | hold on 6 | y2 = cos(2*x); 7 | plot(x,y2) 8 | 9 | legend('cos(x)','cos(2x)') 10 | -------------------------------------------------------------------------------- /load.m: -------------------------------------------------------------------------------- 1 | disp('Contents of workspace before loading file:') 2 | whos 3 | 4 | disp('Contents of gong.mat:') 5 | whos('-file','gong.mat') 6 | 7 | load('gong.mat') 8 | disp('Contents of workspace after loading file:') 9 | whos 10 | -------------------------------------------------------------------------------- /lookfor.m: -------------------------------------------------------------------------------- 1 | lookfor inverse 2 | -------------------------------------------------------------------------------- /matri.m: -------------------------------------------------------------------------------- 1 | a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]; 2 | a(:, 2:3) 3 | -------------------------------------------------------------------------------- /max.m: -------------------------------------------------------------------------------- 1 | A = [23 42 37 18 52]; 2 | M = max(A) -------------------------------------------------------------------------------- /max_min_plot.m: -------------------------------------------------------------------------------- 1 | % Example on how to plot the maxima and minima points on a curve 2 | % Uses findpeaks() method 3 | n = -2*pi:0.01:2*pi; 4 | y = sin((n)); 5 | plot(n,y); 6 | 7 | %plot maxima 8 | [Maxima,MaxIdx] = findpeaks(y); 9 | hold on; 10 | plot(n(MaxIdx),Maxima,'r*'); 11 | 12 | %plot minima 13 | [Minima,MinIdx] = findpeaks(-y); 14 | plot(n(MinIdx),-Minima,'g*'); 15 | hold off; -------------------------------------------------------------------------------- /meshgrid.m: -------------------------------------------------------------------------------- 1 | %transforms our domain (x,y) into rectangular meshes for easy indexing 2 | x=-5:0.1:5; 3 | y=-5:0.1:5; 4 | t=5; 5 | w=1.3; 6 | k=1.3; 7 | [X,Y]=meshgrid(x,y); 8 | R=(X.^2+Y.^2)^1/2; 9 | u=20*cos(k*R+w*t); 10 | surf(X,Y,u); 11 | -------------------------------------------------------------------------------- /mfiles.m: -------------------------------------------------------------------------------- 1 | mkdir progs % create directory progs under default directory 2 | chdir progs % changing the current directory to progs 3 | edit prog1.m % creating an m file named prog1.m 4 | 5 | NoOfStudents = 6000; 6 | TeachingStaff = 150; 7 | NonTeachingStaff = 20; 8 | 9 | Total = NoOfStudents + TeachingStaff ... 10 | + NonTeachingStaff; 11 | disp(Total); -------------------------------------------------------------------------------- /min.m: -------------------------------------------------------------------------------- 1 | A = [23 42 37 15 52]; 2 | M = min(A) -------------------------------------------------------------------------------- /mymax.py: -------------------------------------------------------------------------------- 1 | function max = mymax(n1, n2, n3, n4, n5) 2 | 3 | %This function calculates the maximum of the 4 | % five numbers given as input 5 | max = n1; 6 | if(n2 > max) 7 | max = n2; 8 | end 9 | if(n3 > max) 10 | max = n3; 11 | end 12 | if(n4 > max) 13 | max = n4; 14 | end 15 | if(n5 > max) 16 | max = n5; 17 | end 18 | -------------------------------------------------------------------------------- /one.m: -------------------------------------------------------------------------------- 1 | X = ones(4) 2 | -------------------------------------------------------------------------------- /plot.m: -------------------------------------------------------------------------------- 1 | x = [0:5:100]; 2 | y = x; 3 | plot(x, y) 4 | -------------------------------------------------------------------------------- /plot_examples.m: -------------------------------------------------------------------------------- 1 | %plotting a simple sine function in the interval [0,2*pi] 2 | x = [0:2*pi:100]; 3 | y = sin(x); 4 | plot(x, y) 5 | title('plot of function (sinx)'); 6 | xlabel('Input'); 7 | ylabel('Output'); 8 | figure 9 | %plotting a simple cosine function in the interval [0,pi] 10 | p=[0:pi:100]; 11 | q = cos(p); 12 | plot(p, q) 13 | title('plot of function (cosx)'); 14 | xlabel('Input'); 15 | ylabel('Output'); 16 | figure 17 | %plotting a simple inverse sine function in the interval [-4,4] 18 | m=[-4:4:100]; 19 | n= asin(m); 20 | plot(m, n) 21 | title('plot of function (asinx)'); 22 | xlabel('Input'); 23 | ylabel('Output'); 24 | figure 25 | 26 | %formatting the plot with custom Linewidth and plot color for one of the examples: 27 | b = [0:2*pi:100]; 28 | c = sin(b); 29 | plot(b, c, 'r','Linewidth',1.9 ) 30 | title('plot of function (sinx)'); 31 | xlabel('Input'); 32 | ylabel('Output'); 33 | -------------------------------------------------------------------------------- /pole_zero.m: -------------------------------------------------------------------------------- 1 | clc;clear all;close all 2 | A1 =[1 -1]; 3 | B1 = [1] 4 | figure() 5 | zplane(A1,B1);title('For first order filter') 6 | A2=[1 -2 1]; 7 | B2 =[1]; 8 | figure() 9 | zplane(A2,B2);title('For second order filter'); 10 | figure() 11 | A3=[1 0 -1]; 12 | B3 = [2]; 13 | zplane(A3,B3) 14 | title('For central derivative filter'); -------------------------------------------------------------------------------- /prod.m: -------------------------------------------------------------------------------- 1 | A=[1:3:7;2:3:8;3:3:9] 2 | B = prod(A) -------------------------------------------------------------------------------- /pwd.m: -------------------------------------------------------------------------------- 1 | cd c:\myMATLABFiles 2 | currentFolder = pwd 3 | -------------------------------------------------------------------------------- /readtable.m: -------------------------------------------------------------------------------- 1 | clc 2 | %Reading the given data in .csv into the table (conv_table) 3 | conv_table = readtable('Downloads/Ni_Standard_bulk_sample_loop.csv'); 4 | -------------------------------------------------------------------------------- /reshape.m: -------------------------------------------------------------------------------- 1 | A = 1:10; 2 | B = reshape(A,[5,2]) -------------------------------------------------------------------------------- /save.m: -------------------------------------------------------------------------------- 1 | filename = 'test.mat'; 2 | save(filename) 3 | -------------------------------------------------------------------------------- /scattertosurface.m: -------------------------------------------------------------------------------- 1 | load seamount 2 | step_size = 0.01; 3 | [xq,yq] = meshgrid(min(x)-1:step_size:max(x)+1, min(y)-1:step_size:max(y)+1); 4 | zq = griddata(x,y,z,xq,yq); 5 | mesh(xq,yq,zq) -------------------------------------------------------------------------------- /semilogx.m: -------------------------------------------------------------------------------- 1 | x = logspace(-1,2); 2 | y = x; 3 | semilogx(x,y) 4 | grid on 5 | -------------------------------------------------------------------------------- /semilogy.m: -------------------------------------------------------------------------------- 1 | x = 1:100; 2 | y = x.^2; 3 | semilogy(x,y) 4 | grid on 5 | -------------------------------------------------------------------------------- /short.m: -------------------------------------------------------------------------------- 1 | A = [9 0 -7 5 3 8 -10 4 2]; 2 | B = sort(A) -------------------------------------------------------------------------------- /size.m: -------------------------------------------------------------------------------- 1 | A = rand(2,3,4,5); 2 | sz = size(A) -------------------------------------------------------------------------------- /stairs.m: -------------------------------------------------------------------------------- 1 | X = linspace(0,4*pi,40); 2 | Y = sin(X); 3 | 4 | figure 5 | stairs(Y) 6 | -------------------------------------------------------------------------------- /stem.m: -------------------------------------------------------------------------------- 1 | figure 2 | Y = linspace(-2*pi,2*pi,50); 3 | stem(Y) 4 | -------------------------------------------------------------------------------- /subplot.m: -------------------------------------------------------------------------------- 1 | subplot(2,1,1); 2 | x = linspace(0,10); 3 | y1 = sin(x); 4 | plot(x,y1) 5 | 6 | subplot(2,1,2); 7 | y2 = sin(5*x); 8 | plot(x,y2) 9 | -------------------------------------------------------------------------------- /sum.m: -------------------------------------------------------------------------------- 1 | A = 1:10; 2 | S = sum(A) -------------------------------------------------------------------------------- /switch.m: -------------------------------------------------------------------------------- 1 | clc 2 | %program demonstrating usage of switch function: 3 | x=input('Enter the operand 1: '); 4 | y=input('Enter the operand 2: '); 5 | operator=input('Enter the operator(1 for addition, 2 for substraction): '); 6 | switch operator 7 | case 1 8 | fprintf('The result of additon is: %.2f',x+y); 9 | case 2 10 | fprintf('The result of substraction is: %.2f',x-y); 11 | otherwise 12 | fprintf('Invalid operator!'); 13 | end 14 | -------------------------------------------------------------------------------- /text.m: -------------------------------------------------------------------------------- 1 | x = 0:pi/20:2*pi; 2 | y = sin(x); 3 | plot(x,y) 4 | text(pi,0,'\leftarrow sin(\pi)') 5 | -------------------------------------------------------------------------------- /texture_based_segmentation.m: -------------------------------------------------------------------------------- 1 | %%Read Image: 2 | I = imread(‘b.png’); 3 | figure, imshow(I); 4 | 5 | %%Create texture Image: 6 | E = entropyfilt(I); 7 | Eim = mat2gray(E); 8 | imshow(Eim); 9 | 10 | %%Create mask for bottom texture: 11 | BW1 = im2bw(Eim, .8); 12 | imshow(BW1); 13 | figure, imshow(I); 14 | roughMask = imfill(closeBWao,’holes’); 15 | 16 | %%Segment Top Texture: 17 | imshow(roughMask); 18 | figure, imshow(I); 19 | 20 | %%Segmentation Results: 21 | texture1 = I; 22 | texture1(~mask2) = 0; 23 | texture2 = I; 24 | texture2(mask2) = 0; 25 | imshow(texture1); 26 | figure, imshow(texture2); -------------------------------------------------------------------------------- /title.m: -------------------------------------------------------------------------------- 1 | plot((1:10).^2) 2 | title('My Title') 3 | -------------------------------------------------------------------------------- /transpose.m: -------------------------------------------------------------------------------- 1 | %find transpose of a matrix A [2 3 5] 2 | A=[2 3 5]; 3 | A_t=A'; 4 | disp(A_t); 5 | -------------------------------------------------------------------------------- /type.m: -------------------------------------------------------------------------------- 1 | type(testcase,comp,value) 2 | type(testcase,uit,indices,value) 3 | -------------------------------------------------------------------------------- /whos.m: -------------------------------------------------------------------------------- 1 | whos a* 2 | whos -regexp ion$ 3 | whos -file durer.mat 4 | -------------------------------------------------------------------------------- /xlabel.m: -------------------------------------------------------------------------------- 1 | plot((1:10).^2) 2 | xlabel('Population') 3 | -------------------------------------------------------------------------------- /ylabel.m: -------------------------------------------------------------------------------- 1 | plot((1:10).^2) 2 | ylabel('Population') 3 | --------------------------------------------------------------------------------