Array values assigned to for loop

1 次查看(过去 30 天)
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