Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Can someone help me. Appreantly, my code has a minor mistake..plz help
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
function main()
clear
clc
%Part A%
total = 0;
for n = 1:99
total = total + n*(n+1);
end
fprintf('Total %d\n' , total)
%Part B%
Total = 0;
for z = 1:300
Total = Total + z;
if mod(z,50)==0
disp(Total)
end
end
%Part C%
count = 0;
for i = 1:3
for k = 1:3
A(i,k) = count;
count = count+1;
end
end
A
%Part D%
%------%
function_multiply(1,2,3)
end
function product = function_multiply(arg1, arg2, arg3)
product = arg1*arg2*arg3;
end
5 comentarios
Image Analyst
el 13 de Dic. de 2017
He put the f in there so it says function, not unction. But it now runs without any error. Please specify exactly why you think it has a mistake.
Respuestas (1)
Walter Roberson
el 13 de Dic. de 2017
MATLAB can define functions in two styles. In one style, every 'function' statement has a corresponding 'end' statement. In the other style, no 'function' statement has a corresponding 'end' statement. You cannot use both styles in the same file.
You have 'end' statements for the functions at the end of your file, so every function must have its 'end' statement.
If you match the end statements for your for loops and your if statements, you will find that you have the same number, which is good. The last of those is right before the line that just has
A
on it. At the time you reach that A you have not yet had an end corresponding to the function statement. After that A line, you start a function that has a corresponding end, while the function main is still active. Defining a new function before closing the previous one is permitted to define nested functions. Then you have another such nested function. But after that your file is finished, but you still have not had the end corresponding to function main.
You should either add an end right after the A line, or you should add an end at the bottom of the file, or you should delete the end lines that correspond to the two function you define at the bottom.
0 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!