How to reference entire substring as a string?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have an array of strings in a 4x1 cell format, called textarr, as below:
ExA
ExB
ExC
ExD.exe
I would like to remove the .exe, so I initially tried:
textarr(4) = textarr(4)(1:end-4);
But Matlab did not like the double brackets on the right hand side.
I then tried a method using a temporary variable, like:
lasttemp = textarr(4);
lasttemp = lasttemp(1:end-4);
But this just results in lasttemp becoming a 1x0 cell...
I suspect I am confusing the String itself with elements of a string array. How can I address a String inside a specific element of an array?
댓글 수: 1
Stephen23
2019년 11월 27일
If those strings represent filenames then using indexing is not a robust solution (because file extensions do NOT all have three characters!). The simple, robust, easy MATLAB solution to remove the file extensions is to use fileparts.
채택된 답변
JESUS DAVID ARIZA ROYETH
2019년 11월 27일
solution:
textarr={'ExA';
'ExB';
'ExC';
'ExD.exe'}
textarr=strrep(textarr,'.exe','')%remove
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!