Having trouble taking the mean of my list

1 view (last 30 days)
I want to create a function called E7stats, which performs a simple statistical analysis on the scores of the first midterm, contained in a csv file. The function takes one string input, filename, which is the name of the csv file, and returns one output, a 1⇥2 structure array S , both of whose two entries contain four fields mean, std d ev, max, and min, which are the mean, standard deviation, maximum value and minimum value of the electronic and paper based midterm scores. The function also creates two histograms of the two midterm 1 scores with 30 equally-sized bins. The Scores of electronic and paper based midterm 1 are stored in the first and second columns in the CSV
My problem is that I get the error:
"mean" previously appeared to be used as a function or command, conflicting with its use here as the name of a variable. A possible cause of this error is that you forgot to initialize the variable, or you have initialized it implicitly using load or eval.
and I know WHY i get the error but I don't know how to fix it because as stated above my variables need to be named mean,min, max. any suggestions welcome. thanks!
function S= E7stats(filename)
filename='grades_E7MT1.csv';
S=csvread(filename,1,0);
stddev = std(S)
mean= mean(S)
min= min(S)
max= max(S)

Accepted Answer

Image Analyst
Image Analyst on 21 Nov 2012
Edited: Image Analyst on 21 Nov 2012
Try it this way:
function S = E7stats(filename)
%filename='grades_E7MT1.csv';
array2D= csvread(filename,1,0);
S.stddev = std(array2D(:))
S.mean = mean(array2D(:))
S.min = min(array2D(:))
S.max = max(array2D(:))
  3 Comments
Matthew
Matthew on 21 Nov 2012
I actually figured it out: I needed to return my values in a structure array! appreciate the help though.
Image Analyst
Image Analyst on 21 Nov 2012
Right - I didn't read carefully enough. I edited it to be what you probably also have by now.

Sign in to comment.

More Answers (1)

Thomas
Thomas on 21 Nov 2012
Edited: Thomas on 21 Nov 2012
You are redefining the functions mean, min and max. It will not work unless you change the names of those variables..

Community Treasure Hunt

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

Start Hunting!