Borrar filtros
Borrar filtros

writing strrep statement within a loop

4 visualizaciones (últimos 30 días)
Jan
Jan el 17 de Abr. de 2012
cd (PATHIN)
%read in all -vhdr files
list=dir('*.vhdr');
len=length(list);
SUBJ=cell(1,len);
for s=1:len
SUBJ{s}=strrep(?, ?, [list(s).name,'.vhdr'] );%%%%%!!
[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;
EEG = pop_loadbv(PATHIN,[SUBJ{s}, '.vhdr'], [], [29]);
In the MATLAB help document it says
modifiedStr = strrep(origStr, oldSubstr, newSubstr)
replaces all occurrences of the string oldSubstr within string origStr with the string newSubstr. But within a loop I´m not sure how I can define the oldSubstr and what I can put down as origStr assuming I have assigned [list(s).name, ´.vhdr´] correctly as the newSubstr? It doesn´t seem to be as simple as the given examples.
Thanks for the help!

Respuestas (3)

per isakson
per isakson el 17 de Abr. de 2012
Did you study the examples of strrep in the online help?
I'm not sure I understand what you want to achieve with strrep. I guess you want to create a modified file specification.
modified_filespec = strrep( [list(s).name,'.vhdr'], 'a', 'b' );
will replace all 'a' by 'b' and return the result in modified_filespec.
  1 comentario
Jan
Jan el 18 de Abr. de 2012
I did, but they are not working within loops. With strrep I want to replace the numbers represented by s with the actual file names. Do I have to write an array of the file names anyway to replace it with?

Iniciar sesión para comentar.


Jan
Jan el 18 de Abr. de 2012
Please post explicitely, what you have as inputs and what you want as output in:
SUBJ{s} = strrep(?, ?, [list(s).name, '.vhdr']);
It is impossible to guess, what the question marks mean.
E.g. if you want to remove the '9' from 'file9.vhdr':
strrep('file9.vhdr', '9', '')

Jan
Jan el 18 de Abr. de 2012
I understand the basic concept of replacing or removing parts of an existing string but if i have an array of s (1 to 50) for eg., and in each iteration of the loop i want to replace s with 1, then 2, then 3 and so on, there must be a way to specify that.. right? just writing s won´t do.
and then if i want to replace the 1, 2, and 3 with file names coded for by list.name, my question was, do i have to write out each file name or just assign list.name to that position
i figured out that strrep isn´t even necessary. now i am using simply list.name each time i want to enter the file name. it´s value will change in each loop because i moved the definition of list.name to within the first loop where it´s value is reassigned after each iteration.
thanks for the help anyway. i appreciate it.
  2 comentarios
per isakson
per isakson el 18 de Abr. de 2012
I still don't understand what you want to achieve. However, to the best of my knowledge strrep is **not** affected by the loop; something that works outside a loop will work inside a loop. All arguments of strrep must be characters. Thus a number represented by a double, e.g. s, must be converted to a string.
Jan
Jan el 19 de Abr. de 2012
I do not understand the question also. What does "replace 1, 2 and 3 with file names" eactly mean?
"list(s).name" is the s'th file name. Does this information help?

Iniciar sesión para comentar.

Categorías

Más información sobre Parametric Spectral Estimation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by