I want to compare two strings from two structs. My Code is like below:
%matlab model scan
[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 is a struct 1x15 with 1 field
my_workspace is 1x1 struct with 20 fields
I got only one variable as return. What is wrong in this code?
f = fieldnames(my_workspace)? do you meanf = 1:numel(fieldnames(my_workspace))?result? That's pretty normal as you override it everytime you loop. Try changingresulttoresult{c}