Array values assigned to for loop

조회 수: 1 (최근 30일)
Garry Dunlap
Garry Dunlap 2022년 10월 27일
편집: Eric Delgado 2022년 10월 28일
t = truss(X, edges, k)
% t: tension in edges
t = [-0.5 ; 1.5811 ; -1.5811]
% yield strength
sigmay = 0.3;
A = edgeArea;
T = sigmay .* A;
N=1;
for i = t(N):t(N+1,:)
if i > 0 ; i < T;
disp(i)
disp('edge does not yield')
elseif i > T;
disp(i)
disp('edge yeilds')
else i < 0;
disp(i)
disp('edge is negative, check buckle')
end
end
I want to run the code so the value of t(1) [-0.5] is ran and solved and displayed then t(2) [1.5811] is and then finally t(3) [-1.5811].

답변 (1개)

Eric Delgado
Eric Delgado 2022년 10월 28일
편집: Eric Delgado 2022년 10월 28일
Try this...
t = [-0.5; 1.5811; -1.5811];
T = 1;
for i = 1:numel(t)
if t(i) > 0 & t(i) < T
msg = 'edge does not yield';
elseif t(i) > T
msg = 'edge yeilds';
else
msg = 'edge is negative, check buckle';
end
fprintf('%.4f - %s\n', t(i), msg)
end
-0.5000 - edge is negative, check buckle 1.5811 - edge yeilds -1.5811 - edge is negative, check buckle

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by