How to find first non repeated (unique) character in a string?
Show older comments
I have already tried to find a Matlab function for this but doesnt seem to be one apart from 'unique' which only eliminates duplicates. Any ideas for code on how to do this?
For example, an input of 'hello' would return h or an input of 'radar' would return d.
The unique characters in 'hello' are h,e and o with h being the first in line
The unique character in 'radar' is only d and so this would also be the first
Any help would be appreciated
Accepted Answer
More Answers (1)
Andrei Bobrov
on 14 Feb 2019
1 vote
z = 'hello';
[a,~,c] = unique(z,'stable');
out = a(find(accumarray(c,1) == 1,1));
Categories
Find more on Simulink 3D Animation 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!