numbers 1 to 10 squared in matlab

To square numbers 1 to 10 in MATLAB, you can use a loop and an array to store the squared values. Here's an example code:

main.m
% create an array to store the squared values
squares = zeros(1, 10);

% use a loop to square numbers 1 to 10
for i = 1:10
   squares(i) = i ^ 2;
end

% print the squared values
disp(squares)
192 chars
11 lines

Output:

main.m
squares =

     1     4     9    16    25    36    49    64    81   100
72 chars
4 lines

related categories

gistlibby LogSnag