Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Loop condition (if)
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 ];
1 Commento
Walter Roberson
il 7 Mar 2018
Duplicated by later https://www.mathworks.com/matlabcentral/answers/386764-loop-condition-if which appears to have a correction
Risposte (0)
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!