Multiplying a string with 1 or 0
조회 수: 11 (최근 30일)
이전 댓글 표시
Check_B = 0; % checks if condition for B is satisfied
string = strcat('A', Check_B*'+B')
I want to be able to add one string to another only if a condition is satisfied, without making an if statement or switch statement.
If Check_B = 0, ('+B') will not be added, otherwise it will be.
The code provided works, however it gives a warning.
Is there a cleaner way to do the same? (I believe this is possible in Python for example)
댓글 수: 0
채택된 답변
the cyclist
2019년 12월 9일
편집: the cyclist
2019년 12월 9일
Here is one way:
c = ['A', repmat('+B',Check_B)];
댓글 수: 1
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!