diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2024-12-21 19:50:20 +0100 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2024-12-21 19:50:20 +0100 |
| commit | 8b711a92ed5d955e88cdc5e625df9b2a547731a0 (patch) | |
| tree | b03ba4314b8a45ed44858f7216d4931834beb2ee /Functions/specialMatrix.m | |
| parent | b0425f98abdb566ba66bf593b8e66dbc4f5a4d95 (diff) | |
re-organized files
Diffstat (limited to 'Functions/specialMatrix.m')
| -rw-r--r-- | Functions/specialMatrix.m | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Functions/specialMatrix.m b/Functions/specialMatrix.m new file mode 100644 index 0000000..d6c31f8 --- /dev/null +++ b/Functions/specialMatrix.m @@ -0,0 +1,51 @@ +function [A] = specialMatrix(n,m) +% This function should return a matrix A as described in the problem statement +% Inputs n is the number of rows, and m the number of columns +% It is recomended to first create the matrxix A of the correct size, filling it with zeros to start with is not a bad choice + +%-------------------------------------------- + +if nargin ~= 2 + error('Error: Please enter two arguments.') +end +if (n|m) <= 0 + error('Error: Index error. Arguments must be positive integers or logical values.') +end + +A = zeros(n,m); %Creates a "blank" n x m matrix full of zeros + +% Now the real challenge is to fill in the correct values of A + +A(1,:) = 1:m; %Lables the first row with column numbers +A(:,1) = 1:n; %Lables the first column with row numbers + +for j = 2:n + for k = 2:m + A(j,k)=A(j-1,k)+A(j,k-1); % fills each element of the matrix with the sum of the left and above element. + end +end +end + +%--------------------------------------------- + +%{ +if nargin(specialMatrix) ~= 2 + error('Error: Please enter two arguments.') +elseif nargin(specialMatrix) <= 0 + error('Error: Index errer. Argument must be positive integers or logical values.') +end + +if n<2 + A = [1:m]; %If matrix is 1 x m then make a matrix with 1 row. +else + A = [1:m;1:m]; %Create row 1 +end + +for j = 3:n %Loop to make + A(j,:) = sum(A); % +end % +A(:,1)=(1:n); + +end +% Things beyond here are outside of your functions +%}
\ No newline at end of file |
