Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

comparing rows in cell array

1 visualización (últimos 30 días)
Jonathan
Jonathan el 27 de Feb. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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
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
Fangjun Jiang el 27 de Feb. de 2020
unique(Allcases,'rows') might be easier.
  7 comentarios
Jonathan
Jonathan el 29 de Feb. de 2020
Hi, thanks for the answer.
However, I have just tried this and it is telling me that the matrix dimensions must agree. I checked the dimensions and both are 1x5 cell arrays.
Jonathan
Jonathan el 29 de Feb. de 2020
oh don't worry. Just figured it out - i was using strings, not numbers!
Thanks you so much for all your help. Now i've learnt how to index cell arrays.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by