注:本文档为个人复习用,请勿随意点踩,谢谢。
设计的函数只给出语法和说明,具体函数请查阅matlab帮助文档。
题目1:
Problem 967. Split a string into chunks of specified length
![](https://img-blog.csdnimg.cn/e46e4ba1c99f457481a4378aff9aa18b.png)
求解得到的优秀代码:
function ans = break_string(s,b)
regexp(s,sprintf(
'(.{%d})',b),
'tokens',
'once');
end
说实话这个代码没看懂,涉及到正则表达式,不是很明白。
学到的函数:
1、regexp : 匹配正则表达式(区分大小写)
![](https://img-blog.csdnimg.cn/8402005ff2564a43be66f06e6c0b6d71.png)
2、celldisp :显示元胞数组内容
![](https://img-blog.csdnimg.cn/1633e373abdf48f99c04b1ee388b7287.png)
3、sprintf : 将数据格式化为字符串或字符向量
![](https://img-blog.csdnimg.cn/54e042b6bcda4a789205072a53553113.png)
4、round : 四舍五入为最近的小数或整数
![](https://img-blog.csdnimg.cn/be563e6ac16147b3834e5bcf908246f6.png)
题目2:
Problem 1899. Convert a Cell Array into an Array
![](https://img-blog.csdnimg.cn/696575b4e34145f3bda4acd42d92b8e1.png)
求解得到的优秀代码:
function y = your_fcn_name(x)
y = strjoin(x,
'');
end
学到的函数:
1、strjoin : 联接数组中的字符串
![](https://img-blog.csdnimg.cn/5c63421513854b5ba0c31d4a70074c02.png)
题目3:
Problem 1971. Remove element(s) from cell array
![](https://img-blog.csdnimg.cn/b602d8def8544c31b9595bfbb8c8bd0b.png)
求解得到的较优代码:
function y = remove_from_cell_array(x,to_remove)
x(to_remove) = [];
y = x;
end
学到的函数: