Extracting Data from Figures and Vectors

8 Ansichten (letzte 30 Tage)
Scott Banks
Scott Banks am 22 Jan. 2025
Kommentiert: Star Strider am 23 Jan. 2025
Dear all,
I have the following code in which I want to extracxt y values (displacements) for 12ft, 24ft and 36ft along a 48ft beam.
clear, clc, close all
EI = 29000*13400; % Flexural rigidity
L = 48; % Length of Beam
P = 1; % Loading
R1y = 0.75; % Support reaction at support 1
R2y = 0.25; % Support reaction at support 2
x1 = 0:0.1:12; % X values for 0 < x < 12
dx1 = x1(2) - x1(1); % Step size
x2 = 12:0.1:48; % X values for 0 < x < 12
Mx1 = R1y*x1/(EI); % Moment function for x1
dx2 = x2(2) - x2(1); % Step size
Mx2 = (R1y*x2 - P*(x2-12))/(EI); % Moment function for x2
y1(1) = 0; % Initial condition for y1
b = 36;
z1(1) = P*b*(L^2 - b^2)/(6*L*EI); % Initial condition for z1 (slope)
% Compute displacement for 0 < x1 < 12
for i = 1:length(x1)-1
y1(i+1) = y1(i) + z1(i)*dx1;
z1(i+1) = z1(i) - Mx1(i)*dx1;
end
y2(1) = y1(end) % Initial condition for y2
z2(1) = z1(end) % Initial condition for z2 (slope)
% Compute displacement for 12 < x2 < 48
for i = 1:length(x2)-1
y2(i+1) = y2(i) + z2(i)*dx2;
z2(i+1) = z2(i) - Mx2(i)*dx2;
end
% Plot results
plot(x1,y1,x2,y2)
grid on
My y1 vector is 121 interations long and my y2 vector is 361 iterations long. How do I extract from the data the values at 12ft, 24ft and 36ft of the beam in the most efficient way? If for example I put y1(12) I do not get the value at 12ft along the 48ft beam, because I have made a step size 0.1 and not 1.
Many thanks in advance,
Scott

Akzeptierte Antwort

Star Strider
Star Strider am 22 Jan. 2025
The easiest way is to use the interp1 function —
clear, clc, close all
EI = 29000*13400; % Flexural rigidity
L = 48; % Length of Beam
P = 1; % Loading
R1y = 0.75; % Support reaction at support 1
R2y = 0.25; % Support reaction at support 2
x1 = 0:0.1:12; % X values for 0 < x < 12
dx1 = x1(2) - x1(1); % Step size
x2 = 12:0.1:48; % X values for 0 < x < 12
Mx1 = R1y*x1/(EI); % Moment function for x1
dx2 = x2(2) - x2(1); % Step size
Mx2 = (R1y*x2 - P*(x2-12))/(EI); % Moment function for x2
y1(1) = 0; % Initial condition for y1
b = 36;
z1(1) = P*b*(L^2 - b^2)/(6*L*EI); % Initial condition for z1 (slope)
% Compute displacement for 0 < x1 < 12
for i = 1:length(x1)-1
y1(i+1) = y1(i) + z1(i)*dx1;
z1(i+1) = z1(i) - Mx1(i)*dx1;
end
y2(1) = y1(end) % Initial condition for y2
y2 = 3.3489e-06
z2(1) = z1(end) % Initial condition for z2 (slope)
z2 = 1.8644e-07
% Compute displacement for 12 < x2 < 48
for i = 1:length(x2)-1
y2(i+1) = y2(i) + z2(i)*dx2;
z2(i+1) = z2(i) - Mx2(i)*dx2;
end
x2_vals = [12 24 36]; % Independent Variable Values
y2_vals = interp1(x2, y2, x2_vals) % Interpolated Dependent Variable Values
y2_vals = 1×3
1.0e-05 * 0.3349 0.4113 0.2645
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Plot results
plot(x1,y1,x2,y2)
hold on
plot(x2_vals, y2_vals, 'rs')
hold off
grid on
.
  6 Kommentare
Scott Banks
Scott Banks am 22 Jan. 2025
That's fine. Thanks for that, Star Strider.
Star Strider
Star Strider am 23 Jan. 2025
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink 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