I have a 646x108 array of 646 student responses to 108 exam questions. It was a MCQ exam and all the responses are A, B, C, or D, so those letters are the contents of the cell array. I've been instructed to create a graph similar to the following one:
I was told that the 'bar' function would work. However, it would not work with the cell array.
I tried changing it to an array of double where A was converted to 1, B to 2, C to 3, D to 4. However, that still didn't work. It seemed to be not treating the responses as categorical, but averaging across the responses.
When I'm working in the cell format, the data looks like this:
In other words, on Q1 person 1 answered A, and person 2 answered B. On Q2 both students answered D.
When I converted that to double, the A became a 1, the B a 2, and so on.
Try this. First I created some sample data, for 10 students answering 5 questions:
Then to find the frequency of each answer to each question,
freq
, I looked at each response individually, and counted up how many students gave that answer to that question. That givesfreq
, an array with 4 rows (one for each possible answer) and 5 columns (one for each question).Then to do the bar plot, you have to take the transpose of
freq
, and I divided it by the number of students so that the bars have height 1.As a side note,
freq
can also be calculated without afor
loopbut it's not very readable or efficient.