How to bulid multiple loops with logic operators

조회 수: 3 (최근 30일)
Kim Leithoff
Kim Leithoff 2020년 6월 28일
답변: Ameer Hamza 2020년 6월 29일
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
Ameer Hamza 2020년 6월 29일
You mistakenly typed 1i (imaginary number in MATLAB) instead of i
elseif (stress_w1_1(i) > stress_w1_2(1i))
%^ remove this 1

추가 답변 (0개)

카테고리

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