简体   繁体   English

下标分配尺寸不匹配。 在分配字符串时

[英]Subscripted assignment dimension mismatch. in assigning strings

I am trying to assign string into matlab zeros.我正在尝试将字符串分配给 matlab 零。

a = zeros(10);
a(1,:) = 'Hand';

But, I am getting the following error.但是,我收到以下错误。

Subscripted assignment dimension mismatch.

I got the meaning of error.我明白了错误的意思。 But I am trying to assign 'Hand' - which is of length 4. But I have 10*10 array.但我正在尝试分配 'Hand' - 长度为 4。但我有 10*10 数组。

Any help is appreciable任何帮助都是可观的

Your string has length 4, but the place you're trying to assign it to has length 10, so that is why you're getting the error.您的字符串长度为 4,但您尝试将其分配到的位置长度为 10,因此这就是您收到错误的原因。 (You can check the dimensions using size() ) Try (您可以使用size()检查尺寸)尝试

a(1,1:4) = 'Hand';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM