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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Voss
Voss il 30 Ago 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 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by