Filter löschen
Filter löschen

Loop condition (if)

1 Ansicht (letzte 30 Tage)
laith Farhan
laith Farhan am 7 Mär. 2018
Beantwortet: laith Farhan am 7 Mär. 2018
clc;
clear all;
close all;
A=[22 40 55 72;
33 55 32 67;
45 40 23 65;
22 40 55 45
];
L1=[3 5 60 3;
2 7 6 43;
5 5 45 56;
3 5 55 34
];
E=[0.52 0.3 0.7 0.45;
0.2 0.11 0.6 0.2;
0.1 0.32 0.45 0.33;
0.51 0.31 0.79 0.2
];
matrix=[1 1 1 1;
1 1 1 1;
1 1 1 1;
1 1 1 1
];
for j1=1:length(A)
j1
B1 = unique(A(:,j1));
B=B1(B1>0);
for i1=1:length(B)
Loci=[];v1=[];
Loci=find(A(:,j1)==B(i1));
if length(Loci)>1
[m a1]=(max(L1(Loci,j1)));
Z1 = unique(L1(Loci,j1));
Z2=[];
Z2=Z1(Z1>0);
for z=1:length(Z2)
Lociz=[];
Lociz = find(L1(Loci,j1)==Z2(z));
if length(Lociz)>1
[m2 a2]=(min(E(Lociz,j1)));
matrix(Lociz(a2),j1)=0;
end
end
matrix(Loci(a1),j1)=0;
end
end
end
Dear Friends,
This is my code and it contains 3 arrays (A, L1, E). First loop checks if there are two or more numbers are similar in each column, then my second loop go to check the location of these similar number in array L1, and make the higher number of these similar = 0 and put it in matrix. In case if we have another similar number in L1, then our code should check the location of these similar number in E, and takes the minimum number of these location = 0 and put it in matrix.
Please help me with this code ??
The expected result should be :
matrix=[1 0 0 1;
1 1 1 1;
1 1 1 1;
0 1 1 1
];

Antworten (1)

laith Farhan
laith Farhan am 7 Mär. 2018
Dear Walter, May I know why you closed the question? its simple and I did my code, I just want someone to tell me , why my code is not working?
Thanks a lot

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by