Create a vector using the even elements of another.
显示 更早的评论
Hello,
I am trying to create a code to analyze Prandtl's lifting line thereom. The prompt calls for descritizing a wingspan into N nodes, where N must be an even number (100, 200, etc.). The nodes alternate "closed" and "open" (just for the sake of clarity). Each of the closed nodes are located at yj, where j = 1,3,5,...,N+1. The formula for finding the y position for every node along the wingspan is provided in the first for loop of my sample code.
Just to get my code running, I set N to 100, therefore there are 51 closed nodes. However, when I try to create a vector, yj, using only the odd elements from my y_pos vector, it alternates the correct value of yj and 0. I understand why it is doing this, but I'm at a loss on how to create a vector that only contains the odd elements from y_pos (i.e. a 51 element vector). Any help would be appreciated, thanks!
b = 10;
N = 100;
j = 1:2:N+1;
del_y = b/N;
for i = 1:1:N+1
y_pos(i) = -(b/2) + (i - 1).*del_y;
for ii = j
yj(ii) = -(b/2) + (ii - 1).*del_y;
end
end
Alternatively, this code just assigns y_pos(1) to every element yj
b = 10;
N = 100;
j = 1:2:N+1;
del_y = b/N;
for i = 1:1:N+1
y_pos(i) = -(b/2) + (i - 1).*del_y;
for ii = 1:1:(N/2)+1
yj(ii) = y_pos(i);
end
end
采纳的回答
更多回答(1 个)
DGM
2022-4-27
If I understand the question correctly:
b = 10;
N = 100;
j = 1:2:N+1;
del_y = b/N;
i = 1:1:N+1;
y_pos = -(b/2) + (i - 1).*del_y; % all elements (101)
y_pos_odd = y_pos(j); % elements from odd indices (51)
类别
在 帮助中心 和 File Exchange 中查找有关 Behavior and Psychophysics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!