Values used to run a for loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Trond Oesten
le 12 Fév 2015
Modifié(e) : Michael Haderlein
le 12 Fév 2015
Hi, I'm trying to model the strength of a cable that consist of N wires, subjected to strain loading (epsilon). To find the strength of the cable I use 2 for loops and some IF sentences. Since I want to find the strength of the cable based on the strain, I want epsilon to start at zero and calculated at certain steps (a in script) towards a described end value (k in script). If I start with epsilon = 0 then I get: Attempted to access jobb(0); index must be a positive integer or logical. Is there a way that my epsilon value can go from zero and I can have smaler calculation steps than 1? The script works when epsilon = 1 and step = 1..
Here is my script:
clc; clear all; close all;
E = 7.75*1e4;
Area = 38.48;
my = 0.8686;
sy = 0.1318;
mu = 0.4343;
su = 0.3295;
k = 8;
a = 1;
N = 200;
epsilon_0 = 0;
jobb = zeros(k,1);
P = rand(N,1);
epsilon_y = logninv(P,my,sy);
epsilon_u_y = logninv(P,mu,su);
epsilon_u = (epsilon_y + epsilon_u_y);
n = numel(P);
g = 1:a:k;
model = zeros(n,1);
for epsilon = (0+epsilon_0):a:k;
for ii = 1:n;
if epsilon_y(ii) >= epsilon
ep = epsilon;
elseif epsilon_y(ii) < epsilon && epsilon < epsilon_u(ii)
ep = epsilon_y(ii);
elseif epsilon_u(ii) <= epsilon
ep = 0;
end
model(ii) = ((ep/100)*E);
end
p = sum(model)*Area;
jobb(epsilon) = p;
end
Best regards
Trond Oesten
0 commentaires
Réponse acceptée
Michael Haderlein
le 12 Fév 2015
Modifié(e) : Michael Haderlein
le 12 Fév 2015
First, you need to distinguish between an index and a value. When you want to assign a value to jobb(epsilon), epsilon is an index. In Matlab, index are integers >=1. Thus, zero is not allowed. In your case, you better create some counter for your outer loop such as you did for the inner loop and work with epsilon(jj) (jj being the counter here). Then, jobb(jj) corresponds to epsilon(jj) and everything is clear.
Apart from that, I think your script can be vectorized. You might want to think about it. If you need help with this respect, please write here again.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!