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

2 ビュー (過去 30 日間)
Scott Banks
Scott Banks 2023 年 8 月 30 日
コメント済み: Voss 2023 年 8 月 31 日
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 件のコメント
Scott Banks
Scott Banks 2023 年 8 月 31 日
Thanks so much, Voss
Voss
Voss 2023 年 8 月 31 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by