Array values assigned to for loop

1 visualización (últimos 30 días)
Garry Dunlap
Garry Dunlap el 27 de Oct. de 2022
Editada: Eric Delgado el 28 de Oct. de 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].

Respuestas (1)

Eric Delgado
Eric Delgado el 28 de Oct. de 2022
Editada: Eric Delgado el 28 de Oct. de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by