%%
%Author: Fan Jinyang
%Date: 2014/4/21

clear; close all; clc

%define the Matrix Size
MatrixSize = 1000;
out = 0;
A = zeros(MatrixSize);

fprintf('--------------------Start-----------------------------\n');

%----------Start calculate time of processing by row-------------------------------------------

%Calculate the time of Setting each number of Matrix
tSetByRow = cputime;
for i = 1 : MatrixSize
    for j = 1 : MatrixSize
        A(i, j) = 1;
    end
end
tSetByRow = cputime - tSetByRow;
fprintf('Time of Setting by row is : %fms.\n', 1000 * tSetByRow);

%Calculate the time of Getting each number of Matrix
tGetByRow = cputime;
for i = 1 : MatrixSize
    for j = 1 : MatrixSize
        out = A(i, j);
    end
end
tGetByRow = cputime - tGetByRow;
fprintf('Time of Getting by row is : %fms.\n', 1000 * tGetByRow);

%Calculate the time of whole process
fprintf('Total time of processing by row is : %fms.\n', 1000 * (tSetByRow + tGetByRow));
%----------End calculate time of processing by row-------------------------------------------

fprintf('------------------------------------------------------\n');

%----------Start calculate time of processing by column----------------------------------------

%Calculate the time of Setting each number of Matrix
tSetByColumn = cputime;
for i = 1 : MatrixSize
    for j = 1 : MatrixSize
        A(j, i) = 1;
    end
end
tSetByColumn = cputime - tSetByColumn;
fprintf('Time of Setting by column is : %fms.\n', 1000 * tSetByColumn);

%Calculate the time of Getting each number of Matrix
tGetByColumn = cputime;
for i = 1 : MatrixSize
    for j = 1 : MatrixSize
        out = A(j, i);
    end
end
tGetByColumn = cputime - tGetByColumn;
fprintf('Time of Getting by column is : %fms.\n', 1000 * tGetByColumn);

%Calculate the time of whole process
fprintf('Total time of processing by column is : %fms.\n', 1000 * (tSetByColumn + tGetByColumn));
%----------End calculate time of processing by column----------------------------------------

fprintf('------------------------------------------------------\n');

%----------Start calculate time of processing by diagonal----------------------------------------

%Calculate the time of Setting each number of diagonal
tSetByDiagonal = cputime;
for i = 1 : MatrixSize
    A(i, j) = 1;
end
tSetByDiagonal = cputime - tSetByDiagonal;
fprintf('Time of Setting by diagonal is : %fms.\n', 1000 * tSetByDiagonal);

%Calculate the time of Getting each number of diagonal
tGetByDiagonal = cputime;
for i = 1 : MatrixSize
    out = A(i, i);
end
tGetByDiagonal = cputime - tGetByDiagonal;
fprintf('Time of Getting by diagonal is : %fms.\n', 1000 * tGetByDiagonal);

%Calculate the time of whole process
fprintf('Total time of processing by diagonal is : %fms.\n', 1000 * (tSetByDiagonal + tGetByDiagonal));
%----------End calculate time of processing by diagonal----------------------------------------

fprintf('------------------------------------------------------\n');

%----------Start calculate time of processing one row----------------------------------------

%Calculate the time of Setting each number of one row
tSetOneRow = cputime;
for i = 1 : MatrixSize
    A(1, i) = 1;
end
tSetOneRow = cputime - tSetOneRow;
fprintf('Time of Setting one row is : %fms.\n', 1000 * tSetOneRow);

%Calculate the time of Getting each number of one row
tGetOneRow = cputime;
for i = 1 : MatrixSize
    out = A(1, i);
end
tGetOneRow = cputime - tGetOneRow;
fprintf('Time of Getting one row is : %fms.\n', 1000 * tGetOneRow);

%Calculate the time of whole process
fprintf('Total time of processing one row is : %fms.\n', 1000 * (tSetOneRow + tGetOneRow));
%----------End calculate time of processing one row----------------------------------------

fprintf('------------------------------------------------------\n');

%----------Start calculate time of processing one column----------------------------------------

%Calculate the time of Setting each number of one column
tSetOneColumn = cputime;
for i = 1 : MatrixSize
    A(i, 1) = 1;
end
tSetOneColumn = cputime - tSetOneColumn;
fprintf('Time of Setting one column is : %fms.\n', 1000 * tSetOneColumn);

%Calculate the time of Getting each number of one column
tGetOneColumn = cputime;
for i = 1 : MatrixSize
    out = A(i, 1);
end
tGetOneColumn = cputime - tGetOneColumn;
fprintf('Time of Getting one column is : %fms.\n', 1000 * tGetOneColumn);

%Calculate the time of whole process
fprintf('Total time of processing one column is : %fms.\n', 1000 * (tSetOneColumn + tGetOneColumn));
%----------End calculate time of processing one column----------------------------------------
