필터 지우기
필터 지우기

Info

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

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

조회 수: 1 (최근 30일)
Mohammed Safwat
Mohammed Safwat 2017년 12월 13일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Image Analyst
Image Analyst 2017년 12월 13일
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 2017년 12월 13일
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...

답변 (1개)

Walter Roberson
Walter Roberson 2017년 12월 13일
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.

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

Community Treasure Hunt

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

Start Hunting!

Translated by