uint8 problem with accuracy?

Hey guys im having an issue with Cody Course work today. This is the prompt for the assignment, it is super simple:
The test suite workspace has two variables A and B described as follows:
The variable A is a 6-element row vector of random integers between 0 and 20. The variable B is a 10-element column vector of random integers between 0 and 50. Write a script that uses A and B to generate the vectors below and assign to the indicated variable names.
Generate a vector named ABrow that is a 16-element row vector consisting of the elements of A followed by the elements of B. Generate a second vector named BAcol that is a 16-element column vector consisting of the elements of ABrow in reverse order. Generate a third vector named FirstHalfA_LastHalfB that is an 8-element row vector consisting of the first 3 elements of A followed by the last 5 elements of B .
I was having problems getting it to accept my solution, it repeatedly gave me the error that Integers can only be combined with integers of the same class, or scalar doubles, which i think i was a problem with the test suite running my program. Anyway, i used the uint8 function, this at least got it to run my program ( note that int8, unit16, and all other variations did not work). Here is my new code below:
% Declare row vector of length 6 with random values upto 20
A = randi([0 20],1,6)
% Declare columnvector of length 10 with random values upto 50
B = randi([0 50],10,1)
%concatnate A and B into new row vector
ABrow=uint8(horzcat(A,B'))
%concatnate A and B into new column vector
BAcol=uint8((fliplr(ABrow))')
%concatnate 3 elements of A and last 5 elements of B into new row vector
FirstHalfA_LastHalfB =uint8([A(1:3),B(6:10)'])
But is weird is that now its telling that one or more elements of the vectors is incorrect, but when I look at the output, it is correct. I think the uint8 functions are distorting my answers so that they dont match? Im not sure what I need to do to get my answer accepted. I will post the test suite for this problem below in case it may shed light on this.
I posted a similar question about half an hour ago, but since the integer problem was solved (i think) this is regarding the other issue

2 个评论

The test suite:
%first test case (check matrix ABrow)
reference.solution;
y_correct = ABrow;
clear ABrow
run('solution');
%test if variables exist and are named correctly
assert(isequal(exist('ABrow','var'),1),['The first variable, ABrow, has not been created. '...
'Check spelling and capitalization.'])
student_sol = ABrow;
%test matrix size
assert(isequal(size(y_correct),size(student_sol)),'Variable ABrow is incorrect length, should be 1x16.')
%test accuracy
test =max(abs(y_correct-student_sol));
assert(le(test,1e-1),['One or more elements in ABrow is incorrect. Double check '...
'operations and that result is assigned to the correct variable name.'])
Duplicate:
https://www.mathworks.com/matlabcentral/answers/333584-integers-can-only-be-combined-with-integers-of-the-same-class-or-scalar-doubles

回答(0 个)

此问题已关闭。

关闭:

2017-4-4

Community Treasure Hunt

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

Start Hunting!

Translated by