Array values assigned to for loop

1 view (last 30 days)
Garry Dunlap
Garry Dunlap on 27 Oct 2022
Edited: Eric Delgado on 28 Oct 2022
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].

Answers (1)

Eric Delgado
Eric Delgado on 28 Oct 2022
Edited: Eric Delgado on 28 Oct 2022
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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!