MATLAB: Getting data from structure

spacestructurewhite space

Hello, I'm using dSPACE to output the results to Matlab. The data comes out as a structure with the variables nested inside. That is fine, but the variable names have spaces in them and I'm not sure how to get the data. And no I cannot change the name of the variables because that is what dSpace/Simulink assign them.
It looks like this:
>> A
A = Platform_HostService: [1×1 struct]
>> A.Platform_HostService
ans =
xAxis: [1x1000 double]
Model Root/Pulse_Generator/Out1: [1x1000 double]
... and so on.
I can't write A.Platform_HostService.Model Root… how do take care of the white space?
Thanks

Best Answer

You can either try to use dynamic field names:
A.Platform_HostService.('Model Root/Pulse_Generator/Out1')
or use FEX: RenameField to rename the fields:
S = A.Platform_HostService;
List = fieldnames(S);
for i = 1:length(List)
S = RenameField(S, List{i}, genvarname(List{i}));
end
Afterwards S is clean. Instead of genvarname you can use this also:
Name = List{i};
newName = Name(isstrprop(Name, 'alphanum'));
[EDITED] Clean all names at first if you use the M-code fallback of RenameField:
S = A.Platform_HostService;
old = fieldnames(S);
new = cell(size(old));
for i = 1:length(old)
new = genvarname(old{i}); % Or the ISSTRPROP method

end
S = RenameField(S, old, new)
Or:
S = A.Platform_HostService;
old = fieldnames(S);
for i = 1:length(old)
new = genvarname(old{i}); % Or the ISSTRPROP method
T.(new) = S.(old{i});
end