I'm trying to create a structure array at runtime in Matlab.
A= {'dark';'oa_45'; 'oa_225'};
for i = 1:3
tmp =load([folder '/' A{i} '.txt']);
eval([A{i} '.count=tmp(:,1:2)']);
eval([A{i} '.mean=mean(tmp(:,1:2),1)']);
eval([A{i} '.sqrtmean=sqrt(' A{i} '.mean)']);
eval([A{i} '.stdev=std(tmp(:,1:2),1)']);
eval(A{i});
end
Since I know, that using eval is a rather bad practice, I would like to know whether there is a simple way to avoid eval here.
I figured it would be possible to create the structure array before the loop and then assign only the sub fields in the loop with the parenthesis notation:
s.(A{i}).count = ...
I found some suggestions here that say, it seems to be possible with subsasgn. That seemed rather more complicated than the eval function.
Does somebody know a simple way to avoid the eval function, or is it just the best call here?
I'm just asking out of curiosity, I guess for these three vectors, the loss in performance doesn't really matter.
Best Regards, Mechanix