Automating the process of accessing multiple excel cells in matlab
Ältere Kommentare anzeigen
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.
Antworten (1)
per isakson
am 24 Okt. 2014
Bearbeitet: per isakson
am 24 Okt. 2014
0 Stimmen
" I want to import and excel document that has names on one column and grades on another column."   Maybe the new data type, table, is suited for your problem. See
- table, Create table from workspace variables
- readtable, Create table from file (reads Excel files)
Kategorien
Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!