Quoted By:
Hello, I am trying to create a pyramid matrix, here is what I have so far:
N = input('Enter an odd integer N: ');
if mod(N, 2) == 0
error('N must be an odd integer.');
end
matrix_width = 2 * N - 1;
pyramid_matrix = zeros(N, matrix_width);
for i = 1:N
for j = 1:matrix_width
distance_to_middle = abs(j - (matrix_width+1)/2);
if distance_to_middle == i - 1
pyramid_matrix(i, j) = i;
end
end
end
disp('Pyramid matrix:');
disp(pyramid_matrix);
Here is the result, I am really lost guys, please help me.
0 0 0 0 1 0 0 0 0
0 0 0 2 2 2 0 0 0
0 0 3 3 3 3 3 0 0
0 4 4 4 4 4 4 4 0
5 5 5 5 5 5 5 5 5