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