Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Voss
Voss am 30 Aug. 2023
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 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by