I have this info_circuitos.Name_circuito. I need to shearch in a name. but the struct have accents. a e i o u OR A E I O U. Could have accent in any of that letter.
I want to create a new info_circuitos.Name_circuito without accent Help pls.
Thanks

2 Kommentare

sixwwwwww
sixwwwwww am 9 Dez. 2013
how many structs you have?
5mid
5mid am 9 Dez. 2013
Bearbeitet: 5mid am 9 Dez. 2013
It can be of any size.
Mónaco
Alemanha Could be like that
Austrália
Monreal
Espanha
Itália

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

sixwwwwww
sixwwwwww am 9 Dez. 2013
Bearbeitet: sixwwwwww am 9 Dez. 2013

2 Stimmen

you can do it like this:
names = {files.name};
str = {'Á', 'É', 'Í', 'Ó', 'Ú', 'á', 'é', 'í', 'ó', 'ú'};
strreplace = {'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'};
for j = 1:length(names)
for i = 1:numel(str)
names{j} = regexprep(names{j}, str{i}, strreplace{i});
end
end
Good luck!

14 Kommentare

5mid
5mid am 9 Dez. 2013
I will try. I have already
nome = input('\nIntroduza o nome do circuito a remover: ','s');
indice_nome = strfind(lower({info_circuitos.Nome_circuito}), lower(nome));
I will try.
Thanks
5mid
5mid am 9 Dez. 2013
But if I search for mona it finds Mónaco?
sixwwwwww
sixwwwwww am 9 Dez. 2013
you are welcome. if you want to avoid the loop then you can use the following method as well:
names = {files.name};
str = '[aeiou]';
startIndex = regexp(names,str);
It will find whether a vowel exist in names and return its starting index
5mid
5mid am 9 Dez. 2013
It will change for example in Austrália the 'á' for a?
I don´t understand how this does that.
5mid
5mid am 9 Dez. 2013
Bearbeitet: 5mid am 9 Dez. 2013
I think I don´t want that. I want like
chars_old = 'ÁÉÍÓÚáéíóú';
chars_new = 'AEIOUaeiou';
str = info.Nome_circuito;
[tf,loc] = ismember(str, chars_old);
str(tf) = chars_new( loc(tf) );
But to change the structure.
sixwwwwww
sixwwwwww am 9 Dez. 2013
I just tried the following code:
names = 'Austrália';
str = '[aeiou]';
startIndex = regexp(names,str);
and it is giving me result:
[2, 8, 9] for u, i and a
It shows that MATLAB is not finding á as a.
5mid
5mid am 9 Dez. 2013
Bearbeitet: 5mid am 9 Dez. 2013
But this don´t change my struct. I think i´m not understanding what you are trying to say to me. This is my struct info.names
Mónaco
Alemanha
Austrália
Monreal
Espanha
Itália
I want it like
Monaco
Alemanha
Australia
Monreal
Espanha
Italia
sixwwwwww
sixwwwwww am 9 Dez. 2013
you can do it as follow:
names = {files.name};
str = {'Á', 'É', 'Í', 'Ó', 'Ú', 'á', 'é', 'í', 'ó', 'ú'};
strreplace = {'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'};
for j = 1:length(names)
for i = 1:numel(str)
names{j} = regexprep(names{j}, str{i}, strreplace{i});
end
end
I hope it solves your problem.
5mid
5mid am 9 Dez. 2013
Bearbeitet: 5mid am 9 Dez. 2013
Man you´re god!!
Thanks, thats what I want.
I can´t choose you answer
sixwwwwww
sixwwwwww am 9 Dez. 2013
Bearbeitet: sixwwwwww am 9 Dez. 2013
you are welcome and why you can't choose my answer?
5mid
5mid am 9 Dez. 2013
forget... The corret option is not the first.
sixwwwwww
sixwwwwww am 9 Dez. 2013
ok i replace it with the correct one
Walter Roberson
Walter Roberson am 9 Dez. 2013
This code does not change the structure, just finds the equivalent strings.
5mid
5mid am 9 Dez. 2013
Yes true, but with that I've done what I want.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 9 Dez. 2013
Bearbeitet: Walter Roberson am 9 Dez. 2013

0 Stimmen

Assuming ISO-8859-1 rather than full Unicode:
This code is untested.
function new_structure = remove_accents_from_struct(old_structure)
% Note: this code is only designed for size(structure) = 1 x 1
% and does not descend recursively into substructures.
old_fields = fieldnames(old_structure);
new_fields = cellfun( @remove_accents_from_string, old_fields, 'Uniform', 0);
if isequal(old_fields, new_fields) %optimization when there are no accents
new_structure = old_structure;
return
end
num_fields = length(old_fields);
% create empty structure populated with the translated field names but not their contents
new_structure = cell2struct( cell( num_fields, 1 ), new_fields );
% now copy the field contents over
for K = 1 : num_fields
new_structure.(new_fields{K}) = new_structure.(old_fields{K});
end
end
function newS = remove_accents_from_string(S)
% table extracted from % http://core.trac.wordpress.org/browser/tags/3.7.1/src/wp-includes/formatting.php
accented_chars = [ ...
char(128), char(131), char(138), char(142), char(154), ...
char(158), char(159), char(162), char(165), char(181), ...
char(192), char(193), char(194), char(195), char(196), ...
char(197), char(199), char(200), char(201), char(202), ...
char(203), char(204), char(205), char(206), char(207), ...
char(209), char(210), char(211), char(212), char(213), ...
char(214), char(216), char(217), char(218), char(219), ...
char(220), char(221), char(224), char(225), char(226), ...
char(227), char(228), char(229), char(231), char(232), ...
char(233), char(234), char(235), char(236), char(237), ...
char(238), char(239), char(241), char(242), char(243), ...
char(244), char(245), char(246), char(248), char(249), ...
char(250), char(251), char(252), char(253), char(255) ];
unaccented_chars = 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy';
newS = S;
[tf, idx] = ismember(S, accented_chars);
newS(tf) = unaccented_chars(idx);
end

2 Kommentare

5mid
5mid am 9 Dez. 2013
Wow to much complex, but should work
Walter Roberson
Walter Roberson am 9 Dez. 2013
You said you could have an accent on any letter, so I could not assume that you only want to deal with grave accents on English vowels.
Most of the rest of the length is comments or efficiency.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 9 Dez. 2013

Kommentiert:

am 9 Dez. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by