Filter löschen
Filter löschen

writing strrep statement within a loop

1 Ansicht (letzte 30 Tage)
Jan
Jan am 17 Apr. 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!

Antworten (3)

per isakson
per isakson am 17 Apr. 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 Kommentar
Jan
Jan am 18 Apr. 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?

Melden Sie sich an, um zu kommentieren.


Jan
Jan am 18 Apr. 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 am 18 Apr. 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 Kommentare
per isakson
per isakson am 18 Apr. 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 am 19 Apr. 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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu EEG/MEG/ECoG finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by