存放不同大小的字符串在MATLAB阵列? [英] Storing strings of different sizes in a MATLAB array?

查看:215
本文介绍了存放不同大小的字符串在MATLAB阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够存储一系列不同尺寸的字符串如

I want to be able to store a series of strings of different sizes such as

userinput = ['AJ48不'; 亚洲公路43号线MANA; AS33 NEWEF'];

这当然是列数每行不同返回一个错误。我知道,是需要这个工作都是在第一和第二行充分的空间。不过,我需要能够把到一个数组这个没有强迫用户加上他/她自己的这些空间。是否有一个命令,让我做到这一点?如果可能的话我也想知道为什么不能与数字如出现这种问题

This of course returns an error as the number of columns differs per row. I'm aware that all that is needed for this to work is adequate spaces in the first and second rows. However I need to be able to put this into an array without forcing the user to add these spaces on his/her own. Is there a command that allows me to do this? If possible I'd also like to know why this problem doesn't arise with numbers e.g.

A = [1; 243; 23524];

推荐答案

您不能用标准的Matlab的数组做到这一点。字符串实际上只是一个在Matlab字符向量。而且你不能有不同长度的行的矩阵。

You cannot do this with standard Matlab arrays. A string is really just a vector of characters in Matlab. And you cannot have a matrix with rows of different lengths.

您可以,但是,使用单元阵列

userinput={'AJ48 NOT'; 'AH43 MANA'; 'AS33 NEWEF'};

disp(userinput{1});

要知道,有很多,其中电池阵列并不像正常的阵列工作的情况。

Be aware that there are many situations where cell arrays don't work like normal arrays.

这篇关于存放不同大小的字符串在MATLAB阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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