Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

comparing rows in cell array

조회 수: 1 (최근 30일)
Jonathan
Jonathan 2020년 2월 27일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Guillaume
Guillaume 2020년 2월 27일
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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2020년 2월 27일
unique(Allcases,'rows') might be easier.
  댓글 수: 7
Jonathan
Jonathan 2020년 2월 29일
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 2020년 2월 29일
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.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by