用字符数分割字符串matlab [英] Splitting string by number of characters matlab

查看:866
本文介绍了用字符数分割字符串matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Matlab中是否有任何内置函数可以按字符数剪切字符串,并将其作为单元格数组或其他形式返回.例如,如果调用A = some_function(string,3):

Is there any builtin function in Matlab that cuts string by the number of characters and returns it as a cell array or something. For example if call A = some_function(string, 3):

Input: string = '1234567890'
Output: A = {'123', '456', '789', '0'}

还是我需要使用循环?

谢谢.

推荐答案

可能有点长:

ns = numel(string);
n = 3;
A = cellstr(reshape([string repmat(' ',1,ceil(ns/n)*n-ns)],n,[])')'

这篇关于用字符数分割字符串matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆