Unable to perform assignment because the left and right sides have a different number of elements. Error in Assignment6ExcelCodyMadsen (line 44) letter(i) = 'B+' ; How do I fix this problem?
조회 수: 1 (최근 30일)
이전 댓글 표시
gradebook = xlsread('Exam_Grades_Data(1)');
display (gradebook);
%%Average Exam Grade for Each Student
% 0 - 59 = E
% 0 - 59 = E
% 0 - 59 = E
% 0 - 59 = E
% 0 - 59 = E
% loopend = length(x)
% loopend = length(grades)
i = 1:5;
average(i) = mean(gradebook(i,1:5));
temp = size(gradebook)
loopend = temp(1,1)
loopend = size(gradebook,1)
for i = 1:loopend
average(i) = mean(gradebook(i,1:5));
end
for i = 1:loopend
if (average(i) <= 59)
letter(i) = 'E' ;
elseif (average(i) <= 69)
letter(i) = 'D' ;
elseif (average(i) <= 75)
letter(i) = 'C' ;
elseif (average(i) <= 79)
letter(i) = 'C+' ;
elseif (average(i) <= 85)
letter(i) = 'B' ;
elseif (average(i) <= 89)
letter(i) = 'B+' ;
else
letter(i) = 'A' ;
end
end
display(Grades)
display(i)
display(average)
display(letter)
댓글 수: 0
답변 (2개)
Stephen23
2018년 10월 10일
편집: Stephen23
2018년 10월 10일
What you are doing will not work: (i) refers to one element of the char array letter, and it is not possible to force multiple characters into one element of a char array: one element is one character. You can use a cell array to store those char vectors:
C = cell(1,loopend); % preallocate cell array.
for k = 1:loopend
if average(k) <= 59
C{k} = 'E';
... ^ ^ curly braces to access cell array contents
end
end
Read more:
Note that you don't need loops or switch for this task:
avg = mean(gradebook(:,1:5),2);
%avg = [0;23;45;67;89;100]; % test values
bin = [0, 60, 70, 75, 80, 85, 90, 100];
mrk = {'E','D','C','C+','B','B+','A'};
[~,idx] = histc(avg,bin);
idx = min(idx,numel(mrk));
out = mrk(idx)
댓글 수: 0
aqsa
2019년 7월 31일
Unable to perform assignment because the size of the left side is 1-by-3377160 and the size of the right side is
1-by-3060288.plz help
댓글 수: 3
aqsa
2019년 7월 31일
% Erxtecting Hog features for all training images and store in a vector
trainingFeatures= zeros(nImages,hogFeatureSize,'single');
for i=1: nImages
img=readimage(imdsTrain,i);
trainingFeatures(i,:)= extractHOGFeatures(img,'CellSize',CellSize);
end
trainingLabels=imdsTrain.Labels;
참고 항목
카테고리
Help Center 및 File Exchange에서 Denoising and Compression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!