Extract same row and columns of matrix
Show older comments
name = ['A1', 'A2', 'A3', 'A4', 'A5', 'A6';...
'B1', 'B2', 'B3', 'B4', 'B5', 'B6';...
'C1', 'C2', 'C3', 'C4', 'C5', 'C6';...
'D1', 'D2', 'D3', 'D4', 'D5', 'D6';...
'E1', 'E2', 'E3', 'E4', 'E5', 'E6';...
'F1', 'F2', 'F3', 'F4', 'F5', 'F6'];
col = 1:6;
row = ['A','B','C','D','E','F'];
all_pcs = zeros(6,6,2);
all_locs = [];
for i = 1:size(xycenters,1)
xc = xycenters(i,1);
yc = xycenters(i,2);
xloc = 0;
for linex = 1:size(xprime,2)
if xc > mean(xprime(:,linex)) && xc < mean(xprime(:,linex+1))
xloc = linex;
end
end
yloc = 0;
for liney = 1:size(yprime,2)
if (yc > mean(yprime(:,liney))) && (yc < mean(yprime(:,liney+1)))
yloc = liney;
end
end
%xloc, yloc
all_pcs(yloc, xloc, :) = [xc, yc];
all_locs = [all_locs;(strcat(row(yloc), num2str(col(xloc))))];
end
disp('There is RedPawn:')
disp(sortrows(all_locs))
Result :
Red pawn :
A2
C4
C4
E4
I just want to extract the twins C4 and put it in other variable. Like this
Result i want :
Red Pawns:
A2
E4
Queen :
C4
Answers (1)
you can find your answer here
Red_pawn={'A2';'C4';'C4';'E4'};
[C ia ic]=unique(Red_pawn,'stable');
c = bsxfun(@eq,ic,ic.');
x = any(tril(c,-1)|triu(c,1),1);
A=x(:);
queen=unique(Red_pawn(A==1))
Red_pawn=unique(Red_pawn(A==0))
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!