Filter löschen
Filter löschen

how to use if with a condition

7 Ansichten (letzte 30 Tage)
Enda Sembiring
Enda Sembiring am 4 Dez. 2020
Beantwortet: Arjun am 12 Sep. 2024 um 8:49
I'm new in using matlab.
for a =1:length(loop1)
for c =1:length(loop1)
if fbtbl1op(a,3) == fbtbl1op(c,3)
ceksama(a,1) = fbtbl1op(a,1);
ceksama(a,2) = fbtbl1op(a,2);
ceksama(a,3) = fbtbl1op(a,3);
ceksama(c,1) = fbtbl1op(c,1);
ceksama(c,2) = fbtbl1op(c,2);
ceksama(c,3) = fbtbl1op(c,3);
end
end
end
i want to do that loop but with condition a is not equal to c. but i cant figure out the function or command needed. can you please help me thanks before hand

Antworten (1)

Arjun
Arjun am 12 Sep. 2024 um 8:49
Hi,
As per my understanding, you want to run the contents of the inner loop only when the condition specified by you is true and “a” is not equal to “c”.
To do this we can extend the “if” condition to incorporate this additional check.
Kindly refer to the following code for better understanding:
for a = 1:length(loop1)
for c = 1:length(loop1)
if fbtbl1op(a,3) == fbtbl1op(c,3) && a ~= c
ceksama(a,1) = fbtbl1op(a,1);
ceksama(a,2) = fbtbl1op(a,2);
ceksama(a,3) = fbtbl1op(a,3);
ceksama(c,1) = fbtbl1op(c,1);
ceksama(c,2) = fbtbl1op(c,2);
ceksama(c,3) = fbtbl1op(c,3);
end
end
end
I hope this will help!

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by