Extracting Data from Figures and Vectors
    2 views (last 30 days)
  
       Show older comments
    
    Scott Banks
 on 22 Jan 2025
  
    
    
    
    
    Commented: Star Strider
      
      
 on 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
0 Comments
Accepted Answer
  Star Strider
      
      
 on 22 Jan 2025
        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
x2_vals = [12 24 36];                                   % Independent Variable Values
y2_vals = interp1(x2, y2, x2_vals)                      % Interpolated Dependent Variable Values
% Plot results
plot(x1,y1,x2,y2)
hold on
plot(x2_vals, y2_vals, 'rs')
hold off
grid on
.
6 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

