How to let 2 vector row to multiply by itself

2 次查看(过去 30 天)
hi I want vector m to multiply with n but for some reason I got this
input(4,7)
i =
4 5 6 7
output =
16 25 36 49
this is my code
function output=input(m,n)
i=m:n
output=i.*i
end
  6 个评论
madhan ravi
madhan ravi 2020-9-17
? Doesn’t prod() do what you want? Or your ”homework” requires a loop?
Dai Nguyen
Dai Nguyen 2020-9-17
my teacher doesn't require a loop at all, but I just wanna create a loop that can adapt to any inputs and still get the same answer.
Sorry I'm really new to matlab and I want to learn a lot from it.
Thank you for your time,

请先登录,再进行评论。

回答(1 个)

madhan ravi
madhan ravi 2020-9-17
编辑:madhan ravi 2020-9-17
m = 4;
n = 7;
prod(m : n)
  1 个评论
Dai Nguyen
Dai Nguyen 2020-9-17
Thank you. I haven't used prod before but this command is pretty awesome, is it stand for product? is there other command that serve the same purpose as prod ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by