Adding Two Arrays Alternatively to make Third Array
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I have two arrays, called "Force X Values" and "Force Y values". I am attaching the files and their pictures respectively.
Force X Values:
Force Y Values:
I want to join these two arrays in such a way that the first value comes from ForceX Values and the second values comes from Force Y values.
The total size of the resultant array wiill be then 128x1. To do it manually, it would look like
Resultant_Array=
[253.756605837273 + 0.00000000000000i
-465.372363772121 + 0.00000000000000i
6.13965893028579 - 3.73527288491552i
11.1240857825471 + 2.09884355966154i]
Does anyone know how to do it using a loop or without it?
2 个评论
Bjorn Gustavsson
2020-8-23
Why? (My guess is that this is a strickly botched programming design. This might come off as rude. My question is why not use the vector-capacity of matlab to have the 2 forces in two different components of the final array? Whenever I've used forces I have used the components to calculate the accellerations in perpendicular directions. That I would achieve like this:
F = [Force_X(:),Force_Y(:)]
That would give you an array F [n_1 x 2] with the force components for one time-step at each row, you would extract them like this:
F_i = F(i1,:);
or interpolate between the time-steps:
F_t = interp1(t,F,t_i);
)
更多回答(1 个)
Jan
2020-8-23
% Arbitrary test data:
ForceX = rand(64, 1) + 1i * rand(64, 1);
ForceY = rand(64, 1) + 1i * rand(64, 1);
% Methode 1:
ForceXY = zeros(128, 1);
ForceXY(1:2:end) = ForceX;
ForceXY(2:2:end) = ForceY;
% Methode 2:
ForceXY = [ForceX.'; ForceY.'];
ForceXY = ForceXY(:);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!