Add Array in a Cell in a For Loop
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fabio Taccaliti
el 26 de Abr. de 2022
Comentada: Fabio Taccaliti
el 26 de Abr. de 2022
Hello,
I would like to add 6 array in a cell (in a new row for each for loop iteration), how can I do it?
The 6 arrays are x_wing, y_wing, z_wing and also x_winglet, y_winglet, z_winglet and the cell is Coordinates that I created outside the loop with the correct dimensions, but when I'm doing Coordinates{i} = {x_wing, y_wing, z_wing, x_wingtip, y_wingtip, z_wingtip}; it filling just the first column of the cell.
This is what I did right now.
Thanks
Coordinates = cell(length(Coo2(:,7)),6);
for i = 1:length(Coo2(:,7))
x = (5:30:95)/100;
x = [x x];
z_wing = (366.2966:15:700-193.7-5)/100;
z_wingtip = (545:30:695)/100;
y = 5*0.18*(0.2969*sqrt(x(1:4))-0.126*x(1:4)-0.3516*x(1:4).^2+0.2843*x(1:4).^3-0.1036*x(1:4).^4);
y = [y -y];
% Angle of Attack
x1 = [0.5+(x(1)-0.5)*cosd(5)-y(1)*sind(5), 0.5+(x(2)-0.5)*cosd(5)-y(2)*sind(5), 0.5+(x(3)-0.5)*cosd(5)-y(3)*sind(5), 0.5+(x(4)-0.5)*cosd(5)-y(4)*sind(5), 0.5+(x(5)-0.5)*cosd(5)-y(5)*sind(5), 0.5+(x(6)-0.5)*cosd(5)-y(6)*sind(5), 0.5+(x(7)-0.5)*cosd(5)-y(7)*sind(5), 0.5+(x(8)-0.5)*cosd(5)-y(8)*sind(5)];
y1 = [(x(1)-0.5)*sind(5)+y(1)*cosd(5), (x(2)-0.5)*sind(5)+y(2)*cosd(5), (x(3)-0.5)*sind(5)+y(3)*cosd(5), (x(4)-0.5)*sind(5)+y(4)*cosd(5), (x(5)-0.5)*sind(5)+y(5)*cosd(5), (x(6)-0.5)*sind(5)+y(6)*cosd(5), (x(7)-0.5)*sind(5)+y(7)*cosd(5), (x(8)-0.5)*sind(5)+y(8)*cosd(5)];
x_wing = x1;
y_wing = y1;
wingtip_angle = Coo2(i,7);
y_1 = -(z_wingtip(1)-5.062) * sind(wingtip_angle);
y_2 = -(z_wingtip(2)-5.062) * sind(wingtip_angle);
y_3 = -(z_wingtip(3)-5.062) * sind(wingtip_angle);
y_4 = -(z_wingtip(4)-5.062) * sind(wingtip_angle);
y_5 = -(z_wingtip(5)-5.062) * sind(wingtip_angle);
y_6 = -(z_wingtip(6)-5.062) * sind(wingtip_angle);
x_wingtip = repmat(x_wing, 6, 1);
y_wingtip = [y_1; y_2; y_3; y_4; y_5; y_6];
y_wingtip = repmat(y_wingtip, 1, 8);
y_wingtip = [y_wingtip(:,1)+y_wing(1)*cosd(wingtip_angle), y_wingtip(:,2)+y_wing(2)*cosd(wingtip_angle), y_wingtip(:,3)+y_wing(3)*cosd(wingtip_angle), y_wingtip(:,4)+y_wing(4)*cosd(wingtip_angle), y_wingtip(:,5)+y_wing(5)*cosd(wingtip_angle), y_wingtip(:,6)+y_wing(6)*cosd(wingtip_angle), y_wingtip(:,7)+y_wing(7)*cosd(wingtip_angle), y_wingtip(:,8)+y_wing(8)*cosd(wingtip_angle)];
z_wingtip = 5.062 + (z_wingtip-5.062) .* cosd(wingtip_angle);
z_wingtip = repmat(z_wingtip, length(x_wing), 1)';
z_wingtip = [z_wingtip(:,1)+y_wing(1)*sind(wingtip_angle), z_wingtip(:,2)+y_wing(2)*sind(wingtip_angle), z_wingtip(:,3)+y_wing(3)*sind(wingtip_angle), z_wingtip(:,4)+y_wing(4)*sind(wingtip_angle), z_wingtip(:,5)+y_wing(5)*sind(wingtip_angle), z_wingtip(:,6)+y_wing(6)*sind(wingtip_angle), z_wingtip(:,7)+y_wing(7)*sind(wingtip_angle), z_wingtip(:,8)+y_wing(8)*sind(wingtip_angle)];
x_wing = repmat(x_wing, 8, 1);
y_wing = repmat(y_wing, 8, 1);
z_wing = repmat(z_wing(3:end), length(x_wing), 1)';
Coordinates{i} = {x_wing, y_wing, z_wing, x_wingtip, y_wingtip, z_wingtip};
clearvars x_wing y_wing z_wing x_wingtip y_wingtip z_wingtip;
end
0 comentarios
Respuesta aceptada
Mohammad Sami
el 26 de Abr. de 2022
Editada: Mohammad Sami
el 26 de Abr. de 2022
Your current code is creating a nested cell array. You can change it as follows.
% for testing %
i = 1;
x_wing = 1;
y_wing = 2;
z_wing = 3;
x_wingtip = 4;
y_wingtip = 5;
z_wingtip = 6;
% change as follows
Coordinates(i,:) = {x_wing, y_wing, z_wing, x_wingtip, y_wingtip, z_wingtip};
% for testing %
i = 2;
Coordinates(i,:) = {x_wing, y_wing, z_wing, x_wingtip, y_wingtip, z_wingtip};
Coordinates
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!