% Initial Inputs
S.P1=[0.1,0.2,0.3]; % Varies in length
S.P2=[3.5,5.5];
S.P3=[7,8,9,10];
C is 50x3 matrix of integer indices to assign values of P1, P2, P3.
for i=1:numel(fieldnames(S))
x{i}=['S.P',num2str(i)];
end
x={'S.P1','S.P2','S.P3'}; %Output of for loop
How to use cell name as variable names to extract the values of P1, P2, P3.
[S.P1(C(:,1)),S.P2(C(:,2)),S.P3(C(:,3))] % Desired Output
How to use variable names generated in for loop to extract data as shown above.