在Matlab中将单元格转换为数组 [英] Convert cell to array in matlab

查看:563
本文介绍了在Matlab中将单元格转换为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大小为400x1的单元格.它基本上由字符串形式的数字组成.我的意思是我这样做的时候

I have a certain cell of size 400x1. It basically consists of numbers in the form of string. I mean when I do

mycell{1}

它给出结果'1'

因此您可以看到数字1是字符串形式.如何将其转换为数字数组?

So you can see the number 1 is in the form of string. How can I convert this into a numeric array?

推荐答案

如果size(mycell)为400x1,则类似于此. . . . .

Like this if the size(mycell) is 400x1 . . . . .

str2num(cell2mat(mycell))

...或者如果尺寸为1x400则类似

... or like this if the size is 1x400

str2num(cell2mat(mycell'))

但是,如果您的任何字符串包含不同数量的字符(即

However, this will cause problems if any of your strings contain a different number of characters, i.e.

mycell{1} = '2'
mycell{2} = '33'

如果您遇到这样的情况,

If you have a case like this,

str2double(mycell)

...似乎可以像其他答案中提到的那样处理此问题!

...seems to handle this ok as mentioned in the other answer!

这篇关于在Matlab中将单元格转换为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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