Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Defining Variables In a Function

조회 수: 1 (최근 30일)
Ethan Hunt
Ethan Hunt 2020년 9월 25일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello,
I have this function with a loop in it and I wish to define the varibles for the function so that every time I run it I get the same results.
function c=LoopVectorAddition(a,b)
c=(a+b);
for index=1,20;
c=a+b;
end
end
Heres my code so far. I'm trying to define a=zeros(1,20) and b=ones(1,20) and no matter where i put it, the program has an issue

답변 (1개)

madhan ravi
madhan ravi 2020년 9월 25일
for index = 1 : numel(a)
c(index) = a(index) + b(index);
end
By the way it’s simply:
c = a + b; % don’t know why you need a loop

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by