How to let 2 vector row to multiply by itself

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

What exactly is the numeric output you desire? Your current code squares each element, which apparently is not what you wanted. Maybe you wanted output = i * n?
like I want it to be like 4x5x6x7 but i wasn't sure how to do it I tried m*i but it will be like (4x4) (4x5) (4x6) (4x7)
I tried to use if command inside the function command, but it won't let me do it. Can you tell me why ? pls maybe I can learn something from it
if m<n
i=m:n
output=
else
i=n:m
output=
? Doesn’t prod() do what you want? Or your ”homework” requires a loop?
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일

1 개 추천

m = 4;
n = 7;
prod(m : n)

댓글 수: 1

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 ?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2020년 9월 17일

댓글:

2020년 9월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by