Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Defining Variables In a Function

1 visualización (últimos 30 días)
Ethan Hunt
Ethan Hunt el 25 de Sept. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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

Respuestas (1)

madhan ravi
madhan ravi el 25 de Sept. de 2020
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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by