writing strrep statement within a loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (3개)
per isakson
2012년 4월 17일
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.
Jan
2012년 4월 18일
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', '')
댓글 수: 0
Jan
2012년 4월 18일
댓글 수: 2
per isakson
2012년 4월 18일
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
2012년 4월 19일
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?
참고 항목
카테고리
Help Center 및 File Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!