Basic question on Round function

3 ビュー (過去 30 日間)
Yossi Sourugeon
Yossi Sourugeon 2015 年 10 月 23 日
コメント済み: Guillaume 2015 年 10 月 23 日
Hello, I got homework in my course Use the floor function on vector A
So they gave me a vector and everything and here hot it looks like A=[2.1 5 8.6 4.5 -2.1] floor (A)
So I run it and it says: Fail This hidden test is visible only to the instructors.
Assertion failed.
why??? It also happens when I use round and ceil
Thanks!
  2 件のコメント
Guillaume
Guillaume 2015 年 10 月 23 日
Have you asssigned the output to the correct variable?
Post the exact code for the entire function you've written rather than letting us guess
Yossi Sourugeon
Yossi Sourugeon 2015 年 10 月 23 日
A=[2.1 5 8.6 4.5 -2.1]; floor(A);

サインインしてコメントする。

回答 (2 件)

Andreas Goser
Andreas Goser 2015 年 10 月 23 日
An assertion on such a simple command looks like a software issue and not your fault. But to be on the safe side, you do excute this as two separate commands, rigtht? or at least with a semicolon?
A=[2.1 5 8.6 4.5 -2.1]; floor (A)
Or
A=[2.1 5 8.6 4.5 -2.1]
floor (A)
  4 件のコメント
Steven Lord
Steven Lord 2015 年 10 月 23 日
My guess is that "Assertion failed." means "assertion" in the xUnit sense or the MATLAB assert function sense rather than the C or C++ function sense.
Guillaume
Guillaume 2015 年 10 月 23 日
'Assertion failed' means that the student's code failed to pass the test set up by the tutor on cody coursework.
In this particular code, the tutor does not want the student to see the actual test. A typical cody test consists would look like this:
%set-up inputs to student's function or script, e.g.:
A=[2.1 5 8.6 4.5 -2.1];
%call student script/function
result = somepredefinedname(A);
%check that the student's code does what it should
assert(isequal(result, [2 5 8 4 -2]));
The student only has to enter his code for somepredefinedname in a text box.

サインインしてコメントする。


Guillaume
Guillaume 2015 年 10 月 23 日
Are you supposed to create a script of a function? If a function where is the function declaration?
In either case, you're not assigning the result of floor to anything. The test in cody is going to look for the result of your answer in a variable. Assign your result to that variable.

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by