필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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
Lokesh Ravindranathan
Lokesh Ravindranathan 2013년 7월 17일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2013년 7월 17일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by