MATLAB错误:“以前似乎是用作函数或命令". [英] MATLAB error: "previously appeared to be used as a function or command"

查看:890
本文介绍了MATLAB错误:“以前似乎是用作函数或命令".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个名为E7stats的函数,该函数对包含在csv文件中的第一个中期分数进行简单的统计分析.该函数接受一个字符串输入,文件名,即csv文件的名称,并返回一个输出,即1⇥2结构数组S,两个数组的两个条目均包含四个字段,分别为std d ev,max和min,这是电子和纸质期中考试成绩的平均值,标准差,最大值和最小值.该函数还创建了两个期中1分数的两个直方图,其中包含30个大小相等的单元格.电子和纸质期中考试1的分数存储在CSV的第一列和第二列中

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:

平均值"以前似乎用作功能或命令, 与此处作为变量名称的使用相冲突. 发生此错误的可能原因是您忘记了初始化 这 变量,或者您已经使用load或隐式初始化了它 评估.

"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.

我知道为什么会收到错误,但我不知道如何解决它,因为如上所述,我的变量需要命名为mean,min,max.任何建议欢迎.谢谢!

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)

我问我的教练:

我们必须在结构数组中显示内容,或者只返回结构数组以及带有字段的'1x2结构数组: 意思是 标准差 最大限度 他回答: 结构是函数的输出.您无需在命令窗口中显示它.只确保它具有正确的字段和值.

we have to display contents in the structure array or should it just return the structure array along with '1x2 struct array with fields: mean stddev max and he replied: the structure is the output of the function. you don't need to display it in the command window. Only make sure it has the correct fields and values.

所以现在我真的对我的函数应该输出什么感到困惑?抱歉给您带来的困惑!

so now i'm really confused on what my function should output? sorry for all the confusion!!

推荐答案

请勿使用函数名称mean()作为变量名称.称为myMean或类似名称.

Don't use the function name mean() as the name of your variable. Call it myMean or something like that.

或者,您也可以创建一个结构,该结构具有诸如均值,最小值和最大值的字段名称:

Or alternatively, you could create a structure that has field names such as mean, min, and max:

d.mean = mean();
d.min  = min();

这篇关于MATLAB错误:“以前似乎是用作函数或命令".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆