I'm not sure how to make the elements of the matrix multiples of 7

2 views (last 30 days)
So basically I need to write a function that makes an mxn martix where the elements are multiples of 7 (7,14,21,...), also m =/= n and they are user inputted positive integers. This is what I have so far:
function [] = matrixQ3(m, n)
prompt='Enter a positive integer for m: ';
m = input(prompt);
prompt1='Enter a positive integer for n that is not equal to the first: ';
n = input(prompt1);
x=0;
while x == 0;
prompt='Enter a new positive integer for m that is not equal to n: ';
m = input(prompt);
prompt1='Enter a new positive integer for n that is not equal to m: ';
n = input(prompt1);
if m ~= n && m > 0 && n > 0;
x=1;
end
end
%z = m * n;
%mat = [m:n, ];
%disp(mat)
end
I am having trouble figuring out how to do the elements part of the matrix.

Accepted Answer

Star Strider
Star Strider on 6 Feb 2016
The randi function to the rescue!
The randi function will give you random integers, so all you then have to do is to decide on the maximum integer, the multiply the result by 7:
m = 3;
n = 4;
Matrix7 = randi(100, m, n) * 7;
A non-random option:
m = 3;
n = 4;
V = 1:(m*n);
Matrix7 = reshape(V', m, n)'*7;

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!