comparing rows in cell array
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
Allcases = readtable('227.xlsx');
caseID = Allcases{:,1};
caseX = Allcases{:,2};
caseY = Allcases{:,3};
i = 1
f = {}
while i<5
g = {caseID(i), caseX(i), caseY(i)}
if *****************:
f = [f;g];
end
i = i+1;
end
Hi, I am trying to build a cell array of unique values. In this case, I am only trying to add the row g to f if it hasn't occured before in f. Could anyone please help me complete the missing code? I am very new to Matlab and have been spending hours to try and fix this problem.
1 comentario
Guillaume
el 27 de Feb. de 2020
Note that:
i = 1;
while i < 5
%... some code that doesn't change i
i = i+5;
end
is more simply written as:
for i = 1:5
%... some code that doesn't change i
end
Respuestas (1)
Fangjun Jiang
el 27 de Feb. de 2020
0 votos
unique(Allcases,'rows') might be easier.
7 comentarios
Jonathan
el 27 de Feb. de 2020
Fangjun Jiang
el 27 de Feb. de 2020
Editada: Fangjun Jiang
el 27 de Feb. de 2020
What is the data type of caseID, caseX and caseY? Might be helpful just providing a simplified data example.
f=[];
g=[1,2,3];
f=[f;g];
g=[1,1,2];
if ~ismember(g,f,'rows')
f=[f;g];
end
Guillaume
el 27 de Feb. de 2020
"Sorry didn't specify but the reason it is more complicated is because I tried to simplify the problem here as part of a bigger project. Because I've got to add other data/changing, unique won't really work."
This explanation is very unclear, you need to provide a lot more details. You can't expect us to keep suggesting methods that make sense with the limited information you provide and then come back with: 'sorry, won't work'.
Jonathan
el 29 de Feb. de 2020
Fangjun Jiang
el 29 de Feb. de 2020
assume it is not a floating point data equal comparison,
if f{end,3}~=g{1,3} || f{end,5}~=g{1,5}
f=[f;g];
end
Jonathan
el 29 de Feb. de 2020
Jonathan
el 29 de Feb. de 2020
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!