2
我想两个字符串由两个结构进行比较。我的代码如下所示:Matlab的:比较的字符串循环
%MATLAB模型扫描
[variables] = Simulink.findVars('myModell');
variablesNames =[];
%save the names of all the variables in variablesNames
for t= 1:length(variables)
variablesNames(t).Name = variables(t).Name;
end
%scan workspace
for f = fieldnames(my_workspace)
found = false;
for c = 1:length(variablesNames)
if strcmp(f{c}, variablesNames(c))
found = true;
result = 'Found in Workspace: ';
end
if ~found
result = 'Not found inside Workspace';
end
end
disp(['Workspace Variable: ', sprintf('%-*s',40,f{c}), result]);
end
variablesNames是一个结构×15与1场
my_workspace是1x1的结构与20场
我只有一个变量作为返回。 这段代码有什么问题?
'f = fieldnames(my_workspace)'?你的意思是'f = 1:numel(fieldnames(my_workspace))'? –
你的意思是“结果”中只有一个值?这是非常正常的,因为您每次循环都会覆盖它。尝试改变'result'到'结果{C}' – BillBokeey
@Ander Biguri:我想你的建议,但请考虑**他妈的是20X1单元。以下是失败:来自非单元格数组对象的单元格内容引用。 错误计算器(13号线) 如果的strcmp(F {C},variablesNames(c))的 – lara