MATLAB使用函数输出转换成另一个函数

时间:2013-10-03 21:27:44

标签: matlab function nested

不确定我做错了什么。我试图将函数crazyGrade的结果用于我的新函数GradeDist但我做错了。

 function [newGrades]=GradeDist(grades)

 newGrades=crazyGrade(grades) 
 % I want to take GradeDist(grades) 
 %and use the parameter grades to pass through crazyGrade 
 %and return it back to this function...but I cant figure that out...


 end
 % I want to use the output of this function in GradeDist
 function newGrades=crazyGrade(grades)
 newGrades=upper(grades) 
 newGrades(grades=='A')='F'; 
 newGrades(grades=='B')='D';
 newGrades(grades=='C')='C';
 newGrades(grades=='D')='B';
 newGrades(grades=='F')='A';
 newGrades(grades=='Y')='W';
 end

当我将GradeDist('A')放入命令行时。我没有得到任何输出。

1 个答案:

答案 0 :(得分:0)

我认为因为我的文件名是crazyGrader函数的名称,当我更改它时它似乎工作。如果有人有兴趣的话,那就是我想要做的事情。

function newwGrades=GradeDist(grade)

newwGrades=crazyGrader(grade)



end



function newGrades=crazyGrader(grades)
newGrades=upper(grades) % convert the string to uppercase letter
% so it will be a string.
newGrades(grades=='A')='F';  % index the grades and replace the grades 
% according to the letter.
newGrades(grades=='B')='D';
newGrades(grades=='C')='C';
newGrades(grades=='D')='B';
newGrades(grades=='F')='A';
newGrades(grades=='Y')='W';
end