Changing variable name within a nested for loop by looping end number in the variable name.
Mostrar comentarios más antiguos
Hello MATLAB community,
Please go throgh the image once, that i have attached.

I want to loop this 'for loop' for 6 cylinders by simply looping PCYL'1' to PCLY'2' and so on such that the variable name itself is changing.
I know two other ways to do this using the 'if' command and changing dataset for every counter until 6 and the other one being copy pasting this 6 times in the same function (not a fan of this).
I understand that my idea might sound absurd but I just wanted to know if this is possible. I tried looking for a similar question but could not find any.
This is the first time I have asked a question on this community, so sorry if I have not followed a specific way to ask a question.
Code:
function [a] = pre_referencing_avg_method(a)
% Input required is the strut file for each sweep. In this case we will
% have 7 files
% THIS FUNCTION IS TO BE USED WHEN MANIFOLD PRESSURE IS CONSTANT
PMAP = 1; %bar
[row] = find(a.PCYL1.axis==-180);
%Pressure referencing cylinder 1
for j = 1:6
for i=1:length(a.PCYL{'j'}.data(1,:))
cycle = a.PCYL1.data(:,i);
avg_pcyl_pre_around_BDC = mean(cycle((row-5):(row+5)));
delta_pre = PMAP - avg_pcyl_pre_around_BDC;
a.referenced_PCYL.CYL{'j'}(:,i)= cycle + delta_pre;
end
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!