
Recently I wrote a few Matlab scripts for the ACC lab. I am going to post them here. If you do not have a valid Matlab license do not despair. All these run successfully on GNU Octave as well which can be downloaded from the following link
https://www.gnu.org/software/octave/
If you are looking for a graphical front end try QtOctave which is also available at the following link
http://sourceforge.net/projects/qtoctave.berlios/
Use any plain text editor like gedit, vi, emacs…… to create the script file and save with a .m extension
All the scripts can be downloaded by clicking on the link below
Click here to download all Matlab Scripts
Script 1:
To find the sum of first ‘N’ numbers that are divisible by 5 and not divisible by 5.The user has to accept the value of ‘N’ from the input device.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Description: Script to find sum of elements divisible by 5
% and sum of elements not divisible by 5 among
% first 'N' integers
% Author: Prabodh C P, Asst.Professor, Dept of CSE, SIT
% Date: 07-12-2013
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
clc;
totsum5=0;
totsum=0;
n=input('Enter number of terms');
fprintf('\nNo of terms is %d\n',n);
for i=1:n,
%V(i) = input('Value');
V(i)=i;
if rem(V(i),5) == 0
totsum5 = totsum5 + V(i);
else
totsum = totsum + V(i);
end
end
for i=1:n,
fprintf('%d\t',V(i));
end
fprintf('\nSum of elements divisible by 5 is %d\n',totsum5);
fprintf('\nSum of elements not divisible by 5 is %d\n',totsum);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% End of script
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Script 2:
To perform row wise and column wise concatenation of two matrices
and to display row number and column number of even elements in a matrix.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Description : Script to perform row wise and column wise
% concatenation of two matrices and to display row
% and column number of even elements in a matrix
%Author : Prabodh C P, Dept of CSE, SIT
%Date : 07-12-2013
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
clc;
m=input('Enter no of rows');
n=input('Enter no of cols');
fprintf('\nEnter elements of Matrix 1\n');
for i=1:m,
for j=1:n;
A(i,j)=input('Value=');
end
end
fprintf('Entered Matrix 1 is\n');
disp(A);
fprintf('\nEnter elements of Matrix 2 is\n');
for i=1:m,
for j=1:n;
B(i,j)=input('Value=');
end
end
fprintf('Entered Matrix 2 is\n');
disp(B);
fprintf('Row wise Concatenation\n');
%C=[A,B];
C=horzcat(A,B);
disp(C);
fprintf('Column wise Concatenation\n');
%D=[A;B];
D=vertcat(A,B);
disp(D);
fprintf('\n');
fprintf('\nEven elements of Matrix 1 is\n');
disp(A);
fprintf('\n');
for i=1:m,
for j=1:n;
if (rem(A(i,j),2)==0)
fprintf('\nElement = %d (row = %d , col = %d)\n',A(i,j),i,j);
end
end
end

excellent work sir