1

I have a cell array Data<1048536x1> of strings in MATLAB. I would like to compare adjacent string elements in the cell array. Is there a function in MATLAB? I tried using strcmp but it only works when you have two strings not for adjacent strings in a cell array. Any help much appreciated.

1 Answer 1

2

To compare every string against the next string, use

sameIdx = find(strcmp(Data(1:end-1),Data(2:end)));

With this, the string at any position of sameIdx is the same as the string at position sameIdx+1. Note that this way, you don't need to check for the same previous string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.