39 views (last 30 days)
Christian Agostino on 23 Feb 2021
Answered: dpb on 24 Feb 2021
I am trying to reassign the values in a number array to letters to appear in a histogram. Attached is the code I wrote. Every time I run it, an error reading
"Unable to perform assignment because the left and right sides have a different number of elements.
Error in Problem_1_392 (line 15)
Can anyone help?
i=1;
end
i=i+1;
end
ylabel('Number of Students')
title('Frequency of ME 392 Grades 2003-2016')
dpb on 23 Feb 2021
The letters Grades aren't numeric at all; wrong idea.

the cyclist on 23 Feb 2021
I'm sorry to say that the approach in your code is so misguided, that it is probably not worth debugging it. You need a different overall approach.
I would think the best one would be to do the histogram on the numeric grades themselves (using the grade cutoffs as the bin edges), and then changing the labels on the resulting histogram to indicate the letter grades.

dpb on 24 Feb 2021
One way that illustrates lookup table approach...
Example usage
ans =
1×20 cell array
{'D'} {'A-'} {'A-'} {'C+'} {'F'} {'C'} {'B+'} {'C-'} {'C+'} {'F'} {'B-'} {'C+'} {'A'} {'A'} {'F'} {'A-'} {'D'} {'F'} {'A-'} {'C+'}
>> [num2cell(grades.');ans] % compare is what wanted...
ans =
2×20 cell array
Columns 1 through 13
{[68.2000]} {[92.1000]} {[94.6000]} {[79.9000]} {[50.4000]} {[75.3000]} {[87.9000]} {[71.9000]} {[77.7000]} {[51.7000]} {[82.9000]} {[79.3000]} {[95.9000]}
{'D' } {'A-' } {'A-' } {'C+' } {'F' } {'C' } {'B+' } {'C-' } {'C+' } {'F' } {'B-' } {'C+' } {'A' }
Columns 14 through 20
{[96.1000]} {[50.7000]} {[93.2000]} {[62.8000]} {[56.7000]} {[90.6000]} {[78]}
{'A' } {'F' } {'A-' } {'D' } {'F' } {'A-' } {'C+'}
>>

### Community Treasure Hunt

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

Start Hunting!