What can this error mean: Undefined function 'ge' for input arguments of type 'cell'. Error in HW6 (line 13) if n(i) >= 0.9

25 views (last 30 days)
I have the following code to read in a spreadsheet interprete the values and write out a letter grade instead of percentage to a new column also sending it back to the 2 of the book, here is the code.
clc;
clear;
[n,t,r] = xlsread ('grades(4).xlsx');
lg = r; %create a new data
lg{1,3} = 'letter';
n = {n mean(n)};
lg{1+length(n), 1} = 'Average';
lg{1+length(n), 2} = 'mean(n)';
for i = 1:length(n);
if n(i) >= 0.9
lg{i+1, 3} ='A'
elseif n(i) >= 0.8
lg{i+1, 3} ='B'
elseif n(i) >= 0.7
lg{i+1, 3} ='C'
elseif n(i) >= 0.6
lg{i+1, 3} ='D'
else
lg{i+1, 3} = 'F'
end
end
xlswrite('grades(4).xlsx', lg, 'Sheet2');
Error message is the following:
Undefined function 'ge' for input arguments of type 'cell'.
Error in HW6 (line 13)
if n(i) >= 0.9
Have tried everything but can't seem to find anything.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Nov 2015
Your command
n = {n mean(n)};
makes n into a cell array, the first element of which is the data read by xlsread() and the second element of which is the result of mean()
for i = 1:length(n);
will then loop with i = 1 and i = 2, because n has become two elements long, with the first one being the result of the xlsread and the second one being the result of mean()
if n(i) >= 0.9
in the first iteration, with i = 1, takes the first subset of the cell array that has two elements, returning a cell array with a single element, in particular the array of numbers that was read by xlsread. It then tries to compare the cell array to a particular numeric value 0.9 . However, comparison operators are not defined for cell arrays so this fails.
Possibly you want
if n{i} >= 0.9
so that you are extracting the content of the first element of the cell array. That would get you the entire numeric array of data read by xlsread. It is legal to compare an entire numeric array to a single numeric value, but doing so usually indicates that you have an error in your logic.
You would have notably fewer problems in your code if you were not creating n as a cell array by using that assignment
n = {n mean(n)};
There is a chance that what you wanted to write was
n = [n; mean(n)];
which would take the mean value of n and append it as an additional row on the bottom of n.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!