How can I remove non unique characters from 2 (or more) character arrays?

1 view (last 30 days)
I would like help writing a script to remove same characters from three or four different character arrays. I have turned strings into character arrays and would like to compare each of the characters from each of the character arrays to see if they are the same. If they are the same, I would like to remove the characters, until all non-unique characters exist. I will then use these non-unique character arrays as the title of the data in the legend of a plot. Here's what I have so far:
These are my character arrays:
DriftEL = char(DriftELHdr);
DriftXEL = char(DriftXELHdr);
DriftLOS = char(DriftLOSHdr);
where:
DriftEL = ta_tsc_tsc_mcs_hk_atc_gyro_drift_el
DriftXEL = ta_tsc_tsc_mcs_hk_atc_gyro_drift_xel
DriftLOS = ta_tsc_tsc_mcs_hk_atc_gyro_drift_los
Since the beginning characters are very similar, I would like to end up with only having el, xel, and los as the remaining characters. I would like to create some type of loop that compares the characters to each other and then removes the non-unique characters. I will be using this again, so I would like it to be dynamic and not just pertain to these character arrays. I'm thinking it would need to be something like this:
for i=1:length(DriftEL)
for j=1:length(DriftXEL)
for k=1:length(DriftLOS)
if DriftEL(i)=DriftXEL(j)=DriftLOS(k)
%Then remove the nonunique characters
end
end
end
end
Any help would be appreciated. Thank you.
  1 Comment
Lokesh Ravindranathan
Lokesh Ravindranathan on 17 Jul 2013
Say if
DriftEL = tsc_tsc_mcs_hk_atc_gyro_drift_el
DriftXEL = ta_tsc_tsc_mcs_hk_atc_gyro_drift_xel,
should the answer be
DriftEL = el
DriftXEL = ta_xel
Otherwise, it could be done with simple comparison.

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 17 Jul 2013
If the part of the strings you want to strip have to be identical beginning from the first character, then this simple algorithm will work:
% The data
DriftEL = 'ta_tsc_tsc_mcs_hk_atc_gyro_drift_el';
DriftXEL = 'ta_tsc_tsc_mcs_hk_atc_gyro_drift_xel';
DriftLOS = 'ta_tsc_tsc_mcs_hk_atc_gyro_drift_los';
% The algorithm [Strip off first character if shared by all others.]
while isequal(DriftEL(1),DriftXEL(1),DriftLOS(1))
DriftEL(1) = [];
DriftXEL(1) = [];
DriftLOS(1) = [];
end

More Answers (0)

Categories

Find more on Multidimensional Arrays 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!