I have a string, after preprocessing i get result as
str=Institution/College
Name;
When i split the string using
str1=regexp(str, '/', 'split')
i get result as [1x11 char] [1x11 char]
str2{2}
gives
College
Name
i need as College Name, i need in one line as College Name
Kindly help

답변 (3개)

Image Analyst
Image Analyst 2016년 3월 27일

1 개 추천

Well don't split it then. Or is the word Institution followed by a slash there and you just want to get rid of that?
str = 'Institution/College Name';
slashLocation = strfind(str, '/');
newStr = str(slashLocation+1:end) % Gives 'College Name'

댓글 수: 6

Pat
Pat 2016년 3월 27일
still i get same result,even i have bigger name
str = 'Department/Institution/College Name';
it doesnot get splitted into two lines,but the before one gets splitted ,why it gets splitted
You don't get the same problem, with College in one cell and Name in another cell. I actually tried it before I posted. Nonetheless, you can use John D'Errico's allwords(), which I use all the time. http://www.mathworks.com/matlabcentral/fileexchange/27184-allwords
str = 'Department/Institution/College Name';
caWords = allwords(str, '/')
caWords =
'Department' 'Institution' 'College Name'
You supply some sentence or string and it splits it into separate cells according to what you say the delimiter is.
Pat
Pat 2016년 3월 27일
after preprocessing i get
i have used find_system(bdroot,'LookUnderMasks','on','FollowLinks', 'on') i get result as
Institution/College
Name
why it gets splitted
Image Analyst
Image Analyst 2016년 3월 27일
편집: Image Analyst 2016년 3월 27일
I don't know what preprocessing you did to produce bdroot, and then I don't what find_system() does to bdroot. Why don't you simple use the code I gave you? It works, doesn't it, whereas your code doesn't.
Walter Roberson
Walter Roberson 2016년 3월 28일
find_system does not split the subsystem names at blanks. It returns a cell array of strings, each with one name. The adjacent entries do not belong together.
It sounds to me as if you have a carriage return (or newline) in a subsystem name. Historically that was not permitted. If it is permitted now, then the carriage return (or newline) would be part of the name and so the name should not be merged onto one line.
Walter Roberson
Walter Roberson 2016년 3월 28일
It appears that under some conditions, spaces and newlines are now permitted; http://www.mathworks.com/help/simulink/ug/accessing-signal-logging-data.html#budgyrh . However, they would still be part of the name. It would be valid to have a signal named 'College Name' (with a space) and a signal named ['College' char(10) 'Name'] (with a newline) in the same block, so putting them on the same line would be misrepresenting the name.

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

KSSV
KSSV 2016년 3월 27일

0 개 추천

Doc strcat

댓글 수: 1

Pat
Pat 2016년 3월 27일
sorry str2{2} gives
College
Name
i need as College Name,strcat doesn't provide result i tried using strcat ,but the result is one string in two lines,i need in one line

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

Stephen23
Stephen23 2016년 3월 28일
편집: Stephen23 2016년 3월 28일

0 개 추천

>> old = sprintf('Institution/College\nName')
old = Institution/College
Name
>> new = regexp(regexprep(old,'\s+',' '),'/','split');
>> new{:}
ans = Institution
ans = College Name

카테고리

도움말 센터File Exchange에서 Modeling에 대해 자세히 알아보기

태그

질문:

Pat
2016년 3월 27일

댓글:

2016년 3월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by