简体   繁体   English

无法执行分配,因为此类型的变量不支持点索引

[英]Unable to perform assignment because dot indexing is not supported for variables of this type

When I run the code below, I get the error " 当我运行下面的代码时,我收到错误“

Unable to perform assignment because dot indexing is not supported for variables of this type. 无法执行分配,因为此类型的变量不支持点索引。

" Any idea on how to fix it? “有关如何修复它的任何想法?

dots.nDots = 100;

for dots = 1:dots.nDots
    dots.x = (rand(1,dots.nDots));   
    dots.y = (rand(1,dots.nDots));
end

The line: 这条线:

dots.nDots = 100;

creates the variable dots as a structure array with a field nDots . 将变量dots创建为具有字段nDots结构数组 However, you overwrite the variable dots when you begin your for loop : 但是,在开始for循环时,您会覆盖变量点:

for dots = 1:dots.nDots

At this point, the variable dots becomes an integer value. 此时,可变dots变为整数值。 When you then try to access the field nDots you get the error you see, because dots is no longer a structure with that field. 当您尝试访问字段nDots您会看到错误,因为dots不再是具有该字段的结构。

If you simply rename your loop variable, you will no longer get that error: 如果只是重命名循环变量,则不会再出现该错误:

dots.nDots = 100;

for iDot = 1:dots.nDots
  dots.x = (rand(1, dots.nDots));   
  dots.y = (rand(1, dots.nDots));
end

However, it's not clear what you hope to accomplish with this loop. 但是,你不清楚你希望用这个循环完成什么。 All this will do is repeatedly overwrite dots.x and dots.y with a new set of 100 random values each, 100 times over. 所有这一切都会重复覆盖dots.xdots.y ,每组100个随机值,100次以上。

暂无
暂无

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

相关问题 MATLAB:访问单元格列时,此类型的变量不支持点索引 - MATLAB: Dot indexing is not supported for variables of this type when accessing a cell column 对于运行良好的代码,“这种类型的变量不支持点索引”? - "Dot indexing is not supported for variables of this type" for a code that was running perfectly fine? 如何修复importdata()结果中的“此类型的变量不支持点索引” - How to fix “Dot indexing is not supported for variables of this type” on importdata()'s results 这种类型的变量不支持大括号索引 - Brace indexing is not supported for variables of this type 我不断收到此错误消息无法执行分配,因为“tf”类型的值不可转换为“单元格”? - I keep get this error message Unable to perform assignment because value of type 'tf' is not convertible to 'cell'? 无法执行分配,因为左侧和右侧具有不同数量的元素 - Unable to perform assignment because the left and right sides have a different number of elements 由于左侧的索引与右侧的大小不兼容,无法执行分配 - Unable to perform assignment because the indices on the left side are not compatible with the size of the right side 无法执行分配,因为左侧和右侧的元素数量不同。 MATLAB 错误 - Unable to perform assignment because the left and right sides have a different number of elements. MATLAB ERROR 无法执行分配,因为左侧的大小为 1×2,右侧的大小为 2×2 - Unable to perform assignment because the size of the left side is 1-by-2 and the size of the right side is 2-by-2 无法执行分配,因为左侧的索引与右侧的大小不兼容。 这是什么意思? - Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. What does this mean?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM