Delete array elements with Coder compatibility
조회 수: 3 (최근 30일)
이전 댓글 표시
I need to delete elements of a string with compatibility for Coder. For example:
myStr = 'This is a fun problem!'
myStr(10) = '';
Now this works just fine in Matlab, but I get an 'The right and left hand sides must have the same number of elements' error when I try to use Coder at the 'Check for Issuse' stage. I realize that I could do the following,
myStr = 'This is a fun problem!'
myStr = myStr([1:9,11:numel(myStr)]);
but this is ugly and challenging because I am doing this as part of a loop where the indexes would get complicated quickly.
Any ideas? Thanks.
댓글 수: 0
채택된 답변
David Hill
2022년 2월 15일
myStr(10)=[];
댓글 수: 3
David Hill
2022년 2월 15일
That syntax [] completely deletes the positions indicated. You can delete entire rows and columns also.
m=randi(100,10);
m(5,:)=[]
m(:,4)=[]
추가 답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!