# How to bulid multiple loops with logic operators

1 view (last 30 days)
Kim Leithoff on 28 Jun 2020
Answered: Ameer Hamza on 29 Jun 2020
Hello everyone,
I am relatively new to Matlab and have a question about the implementation of a logical linkage. My idea was to build it in two loops.
I have a data sheet with two columns. Now I want to compare the first value in column 1 with the first value in column 2.
Depending on whether it is >,< or == I want to apply a certain formula.
This formula must be based on a starting value No. Depending on what the first logical link delivers, No,1 should be calculated, and so on.
When applying the code I get the error:
"Array indices must be positive integers or logical values"
Could someone help me?
Thanks a lot
Kim
This is the Code I got so far:
>> No = 23.393; % in N/n
stress_w1_1=stress_w1(:,1);
stress_w1_2=stress_w1(:,2);
number_w1_1 = size(stress_w1(:,1), 1);
for i=1:number_w1_1 % First Loop
if (stress_w1_1(i) < stress_w1_2(i)) %Second Loop
for x=1:number_w1_1
if x==1
N_limit=No;
elseif x==2:number_w1_1
N_limit=0.9*N_limit;
end
end
elseif (stress_w1_1(i) > stress_w1_2(1i))
for x=1:number_w1_1 %Second Loop
if x==1
N_limit=No;
elseif x==2:number_w1_1
N_limit=1.2*N_limit;
end
end
elseif (stress_w1_1(i) == stress_w1_2(i))
for x=1:number_w1_1 %Second Loop
if x==1
N_limit=No;
elseif x==2:number_w1_1
N_limit=N_limt(x-1);
end
end
end
end

Ameer Hamza on 29 Jun 2020
You mistakenly typed 1i (imaginary number in MATLAB) instead of i
elseif (stress_w1_1(i) > stress_w1_2(1i))
%^ remove this 1