# Code runs but no graphical output

조회 수: 2 (최근 30일)
Peter Bohlen 2023년 12월 1일
댓글: Peter Bohlen 2023년 12월 1일
I am trying to plot the deflection of a beam using MATLAB. My code runs but there is no output on my graph. I am using "for" operation rather than an array, because the array was producing errors. The code is as follows:
E = 200000; % Young's Modulus in N/mm^2
I = 416.667; % Moment on Inertia in mm^2
P = 600; %Applied force in N
Q = 1200; %Applied force in N
L = 3000; %Length of Beam in mm
b = 1000; %Applied location in mm for 600 N
a = 2000; %Applied location in mm for 1200 N
for x=0:10:3000
V = ((-P * b .* x) / (6 * E * I * L)) * (L^2 - b^2 - x.^2) + (((-Q * a .* x) / (6 * E * I * L)) * (L^2 - a^2 - x.^2));
end
plot (V,x)
xlabel 'Distance (mm)'
ylabel '(Deflection mm)'
I have attached a picture of the graph as well as the MATLAB script. Any assistance would be much appreciated!

댓글을 달려면 로그인하십시오.

### 채택된 답변

Walter Roberson 2023년 12월 1일
E = 200000; % Young's Modulus in N/mm^2
I = 416.667; % Moment on Inertia in mm^2
P = 600; %Applied force in N
Q = 1200; %Applied force in N
L = 3000; %Length of Beam in mm
b = 1000; %Applied location in mm for 600 N
a = 2000; %Applied location in mm for 1200 N
xvals = 0:10:3000;
num_x = length(xvals);
for xidx = 1 : num_x
x = xvals(xidx);
V(xidx) = ((-P * b .* x) / (6 * E * I * L)) * (L^2 - b^2 - x.^2) + (((-Q * a .* x) / (6 * E * I * L)) * (L^2 - a^2 - x.^2));
end
plot (xvals, V)
xlabel 'Distance (mm)'
ylabel '(Deflection mm)'
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Peter Bohlen 2023년 12월 1일
Thank you!! Looks like I did not set up the "for" loop correctly.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by