Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Can someone help me. Appreantly, my code has a minor mistake..plz help

1 Ansicht (letzte 30 Tage)
Mohammed Safwat
Mohammed Safwat am 13 Dez. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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 Kommentare
Image Analyst
Image Analyst am 13 Dez. 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.
Mohammed Safwat
Mohammed Safwat am 13 Dez. 2017
After I posted the question, I wrote a comment under it saying I missed the letter F. The problem it is executing, my TA says I might be missing one or two ends and my function syntax is wrong...

Antworten (1)

Walter Roberson
Walter Roberson am 13 Dez. 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.

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by