Multiplying a string with 1 or 0
15 次查看(过去 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!