Matlab “如何修复”;未定义的函数或变量;这个脚本中有错误吗?

Matlab “如何修复”;未定义的函数或变量;这个脚本中有错误吗?,matlab,structure,Matlab,Structure,我正在实现以下功能,以查询名称为“Texas”的所有学院条目: function [] = queryHandler(structName, fieldName, fieldValue) % query for college names for i = 1:1:length(structName.fieldName) if strcmp(structName(i).fieldName, fieldValue) if strcmp(fieldName, 'name

我正在实现以下功能,以查询名称为“Texas”的所有学院条目:

function [] = queryHandler(structName, fieldName, fieldValue)

% query for college names



for i = 1:1:length(structName.fieldName)
    if strcmp(structName(i).fieldName, fieldValue)
        if strcmp(fieldName, 'name')
            foundNames(i) = structName(i);
        elseif strcmp(fieldName, 'nickName')
            foundnickNames(i) = structName(i);
        elseif strcmp(fieldName, 'location')
            foundLoactions(i) = structName(i);

    end
end

if strcmp(fieldName, 'name')
    foundNames
elseif strcmp(fieldName, 'nickName')
    foundnickNames
elseif strcmp(fieldName, 'location')
    foundLocations
end
end
以下是主要脚本:

%collegeDatabase main test script
clc
clear


%preallocation for speed
names = {'Kansas', 'KSU', 'Oklahoma', 'Texas', 'Alabama', 'LSU', 'Mizzou', 'Stanford', 'Auburn', 'Oregon'};
nickNames = {'Jayhawks', 'Wildcats', 'Sooners', 'Longhorns', 'Crimson Tide', 'Tigers', 'Tigers', 'Cardinals', 'Tigers', 'Ducks'};
locations = {'Kansas', 'Kansas', 'Oklahoma', 'Texas', 'Alabama', 'Louisiana', 'Missouri', 'California', 'Alabama', 'Oregon'};

college(10).name = {' '};
college(10).nickName = {' '};
college(10).location = {' '};

%creation of structure for college names, nicknames, loactions

for i = 1:length(names)
    college(i).name = names(i);
    college(i).nickName = nickNames(i);
    college(i).loaction = locations(i);
end

queryHandler(college, name, Texas)

我正在尝试获取这些输入以搜索学院(I)。数据库中的名称为“Texas”。要解决这个问题,我需要对这里的输入做什么?谢谢

首先,在主脚本中,您可能应该调用
queryHandler(college,'name','Texas')

其次,在函数中,应将所有
structName(i).fieldName
调用更改为
structName(i)。(fieldName)

最后,在for循环中,应该转到
structName(0)。(fieldName)
。结构本身没有元素
fieldName
,但每个元素都有