Help with creating an array from two smaller arrays in a for loop

2 次查看(过去 30 天)
Hi guys,
I am trying to create a 12x1 array (Fv) from two 1x6 arrays (Mx1 and Mx2). I want the 12x1 array to be populated by the Mx1 values for the first six rows, and the remaing rows to be populated by the Mx2 values. Here is the code I am using:
n = 12;
X1 = linspace(0,L/2,n/2);
X2 = linspace(L/2,L,n/2);
Mx1 = 25.*X1;
Mx2 = 25.*X2 - 50.*(X2-4);
Ft = ones(n,1)
for i = 1:size(Ft,1)
Fv(i) = Ft(i).*Mx1(i)
if i >= 6
Fv(i) = Ft(i).*Mx2(i)
end
end
I am getting the follwing errors
Fv =
0 20 40 60 80 0
Index exceeds the number of array elements. Index must not exceed 6.
Error in beam_deflection_bvp (line 52)
Fv(i) = Ft(i).*Mx1(i)
Can somebody help please?

采纳的回答

Voss
Voss 2023-8-30
L = 8;
n = 12;
X1 = linspace(0,L/2,n/2);
X2 = linspace(L/2,L,n/2);
Mx1 = 25.*X1;
Mx2 = 25.*X2 - 50.*(X2-4);
Fv = [Mx1 Mx2].'
Fv = 12×1
0 20.0000 40.0000 60.0000 80.0000 100.0000 100.0000 80.0000 60.0000 40.0000
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by