Automating the process of accessing multiple excel cells in matlab

Good day everyone, i have a little problem that requires your help. Here is an overview of what i am trying to do. I want to import and excel document that has names on one column and grades on another column. On each name i want to compare the passing and failing grades. If name A has more A's,B's, than F's, I want it to display U. The S and U would be in a new column NameL A B C D A > becomes NameL A B C D A U Name2 F C W A > becomes Name2 F C W A F S etc I did this at first
[num, txt, raw ] = xlsread(midtermGrades)
Jane = raw(2,2:end)
lengthofJane = numel(Jane)
Elements = strcmp('A', Jane) | strcmp('B', Jane) | strcmp('C', Jane)
findJane = find(Elements) > 0
length = numel(findJane)
if length >= (lengthofJane ./ 2)
disp('Name S/U')
disp( 'Jane S')
else
disp('Name S/U')
disp( 'Jane U')
end
James = raw(4,2:end)
lengthofJames = numel(James)
ElementsJames = strcmp('A', James) | strcmp('B', James) | strcmp('C', James)
findJames = find(ElementsJames)
lengthJames = numel(findJames)
if lengthJames >= (lengthofJames ./2)
disp('Name S/U')
disp( 'James S')
else
disp('Name S/U')
disp( 'James U')
end
Jakes = raw(3,2:end)
lengthofJakes = numel(Jakes)
ElementsJakes = strcmp('A', Jakes) | strcmp('B', Jakes) | strcmp('C', Jakes)
findJakes = find(ElementsJakes)
lengthJakes = numel(findJakes)
if lengthJakes >= (lengthofJakes ./ 2)
disp('Name S/U')
disp( 'James S')
else
disp('Name S/U')
disp( 'James U')
end
then i tried this
clear clc [num, txt, raw] = xlsread('midtermGrades');
[rows cols] = size(raw);
y = raw(2:end,2:end)
p = strcmp('A', y) | strcmp('B', y) | strcmp('C', y) ...
| strcmp('D', y) | strcmp('F', y) | strcmp('W', y)
q = strcmp('A', y) | strcmp('B', y) | strcmp('C', y)
l = find(q) > 0
w = numel(l)
r = numel(p)
if w >= (r ./ 2)
disp('Name S/U')
disp( 'Name S')
else
disp('Name S/U')
disp( 'Name U')
end
But this works fine when only 1 name is entered. I thought if it works for one, it should work for all. Basically if there is one name entered it should compare the number of passing and failing grades, and display U for more passing or S for more failing. But it should do the same with multiple names.
Any help would be appreciated.

Answers (1)

" I want to import and excel document that has names on one column and grades on another column." &nbsp Maybe the new data type, table, is suited for your problem. See

2 Comments

Thanks. I am trying to make the script more dynamic and i went and wrote. I got this
clear
clc
[num,txt,raw] = xlsread('midtermGrades');
a = raw(2:end,1);
b = raw(2:end ,2:end);
c = strcmp('A', b) | strcmp('B', b) | strcmp('C', b);
d = sum(c')
e = int2str(d);
f = strrep(e,'5','S')
g = strrep(f,'4','S')
h = strrep(g,'3','S')
i = strrep(h,'2','U')
j = strrep(i,'1','U')
k = strrep(j,'0','U')'
table(k)
but the problem i experience right now is that when i put it in a table it adds extra spaces. I am trying to have names right beside the letter S or U
I believe the problem i am having is because i am using int2str. Strtrim doesn't seem to work.

Sign in to comment.

Categories

Tags

Asked:

Bee
on 23 Oct 2014

Edited:

on 31 Oct 2014

Community Treasure Hunt

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

Start Hunting!