将字符串中的字符逐个读取到数组中 [英] Reading character by character from a string into an array

查看:173
本文介绍了将字符串中的字符逐个读取到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MATLAB 中将整数逐位读取到数组中的常用方法是什么?

What is the usual way in MATLAB to read an integer into an array, digit by digit?

我正在尝试将四位数的整数1234 分解为数组[1 2 3 4].

I'm trying to split a four digit integer, 1234 into an array [1 2 3 4].

推荐答案

在这里,对于单个整数,这是一种非常简单的方法

Here is a very easy way to do it for a single integer

s = num2str(1234)
for t=length(s):-1:1
   result(t) = str2num(s(t));
end

然而,最紧凑的方式是:

The most compact way however, would be:

'1234'-'0'

这篇关于将字符串中的字符逐个读取到数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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