matlab误差,尝试对非结构阵列进行参考。

时间:2021-05-19 23:13:35

All the references to this error I could find searching online were completely inapplicable to my situation, they were dealing with some kind of variables involving dots, like a.b (structures in other words), whereas I am strictly using arrays. Nothing involves a dot, nor does my code ask about it.

我能在网上搜索到的所有关于这个错误的参考资料都完全不适合我的情况,它们处理的是一些涉及点的变量,比如a。b(结构),而我严格使用数组。什么都不涉及点,我的代码也没有问它。

Ok, I have this GINORMOUS array called tier2comparatorconnectionpoints. It is a 4-D array of size 400×10×20×10. Consider tier2comparatorconnectionpoints(counter,counter2,counter3,counter4).

我有这个巨大的数组,叫做tier2comparatorconnectionpoints。这是一个四维数组大小为400×10×20×10。考虑tier2comparatorconnectionpoints(计数器,counter2、counter3 counter4)。

  • counter is a number 1 to 400,
  • 计数器是1到400,
  • counter2 is a number 1 to numchromosomes(counter), and numchromosomes(counter1) is bound to 10,
  • counter2是数字1到数字染色体(counter),而数字染色体(counter1)与10结合,
  • counter3 is a number 1 to tier2numcomparators(counter,counter2), which is in turn bounded to 20.
  • counter3是tier2numcomparators(counter,counter2)的1号,它的界值依次为20。
  • counter4 is a number 1 to tier2inputspercomparator(counter,counter2,counter3), which is bounded to 10.
  • counter4是tier2inputspercomparator(counter,counter2,counter3)的1号,它被限定为10。

Now, so that I don't run out of RAM, I have tier2comparatorconnectionpoints as type int8, and UNFORTUNATELY at some point in my horrendous amount of code, I forgot to cast it to a double when I'm doing math with it, and a rounding error involved with multiplying it with a rand ends up with tier2comparatorconnectionpoints for some values of its 4 inputs exceeding what it's allowed to be.

现在,所以我不耗尽内存,我tier2comparatorconnectionpoints int8类型,不幸的是在我的可怕的的代码量,我忘了丢给两个当我做数学,和舍入误差参与乘用兰特最终与tier2comparatorconnectionpoints 4输入的值超过它的允许。

The values it's allowed to have are 1 through tier1numcomparators(counter,counter2), which is bounded to 40, 41 through 40+tier2numcomparators(counter,counter2), with tier2numcomparators(counter,counter2) being bounded to 20, and 61 through 60+tier2numcomparators(counter,counter2), thus it's not allowed to be more than 80 since tier2numcomparators(counter,counter2) is bounded to 20 and it's not allowed to be more than 60+tier2numcomparators(counter,counter2), but it's also not allowed to be less than 40 but more than tier1numcomparators(counter,counter2) and it's not allowed to be less than 60 but more than 40+tier2numcomparators(counter,counter2). I became aware of the problem because it was being set to 81 somewhere.

的值是允许通过tier1numcomparators 1(计数器,counter2),这是40岁为界,通过40 + 41 tier2numcomparators(计数器,counter2),与tier2numcomparators(计数器,counter2)20日为界,和61年到60 + tier2numcomparators(计数器,counter2),因此不允许超过80以来tier2numcomparators(计数器,counter2)为界,20,不得超过60 + tier2numcomparators(计数器,counter2),但它也不允许小于40,但是超过了tier1numcomparators(counter,counter2),它不允许小于60,但是超过40+tier2numcomparators(counter,counter2)。我意识到这个问题,因为它被设置为81。

This is an evolutionary simulation by the way, it's natural selection on simulated organisms. I need to hunt down the part of the code that is allowing the values of tier2comparatorconnectionpoints to exceed what it's allowed to be. But that is a separate problem.

顺便说一下,这是一个进化模拟,模拟生物的自然选择。我需要查找代码中允许tier2comparatorconnectionpoints值超过允许值的部分。但这是另一个问题。

A temporary fix of my data, just so that it at least is made to conform to its allowed values, is to set anything that is greater than tier1numcomparators(counter,counter2) but less than 40 to tier1numcomparators(counter,counter2), to set anything that is greater than 40+tier2numcomparators(counter,counter2) but less than 60 to 40+tier2numcomparators(counter,counter2), and to set anything that is greater than 60+tier2numcomparators(counter,counter2) to 60+tier2numcomparators(counter,counter2). I first found this problem because it was being set to 81, so it didn't just exceed 60+tier2numcomparators(counter,counter2), it exceeded 60+20, with tier2numcomparators being bounded to 20.

临时修复我的数据,这样,它至少是由符合其允许的值,是设置任何大于tier1numcomparators(计数器,counter2)但不到40 tier1numcomparators(计数器,counter2),设置任何大于40 + tier2numcomparators(计数器,counter2),但不超过60 - 40 + tier2numcomparators(计数器,counter2),以及设置任何大于60 + tier2numcomparators(计数器,counter2)到60 + tier2numcomparators(计数器,counter2)。我第一次发现这个问题是因为它被设置为81,所以它不只是超过60+tier2numcomparators(counter,counter2),它超过60+20,tier2numcomparators被绑定到20。

I hope this isn't all too-much-information, but I felt it might be necessary to get you to understand just what sort of variables these are.

我希望这不是太多的信息,但我觉得有必要让你了解这些变量是什么。

So in my attempts to at least turn the data into valid data, I did the following:

因此,在我试图至少将数据转化为有效数据的过程中,我做了以下工作:

for counter=1:size(tier2comparatorconnectionpoints,1)
 for counter2=1:size(tier2comparatorconnectionpoints,2)
  for counter3=1:size(tier2comparatorconnectionpoints,3)
   for counter4=1:size(tier2comparatorconnectionpoints,4)
    if tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)>60+tier2numcomparators(counter,counter2)
     tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)=60+tier2numcomparators(counter,counter2);
    end
   end
  end
 end
end

And that worked just fine. And then:

而且效果很好。然后:

for counter=1:size(tier2comparatorconnectionpoints,1)
 for counter2=1:size(tier2comparatorconnectionpoints,2)
  for counter3=1:size(tier2comparatorconnectionpoints,3)
   for counter4=1:size(tier2comparatorconnectionpoints,4)
    if tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)>40+tier2numcomparators(counter,counter2)
     if tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)<60
      tier2comparatorconnectionpoints(counter,counter2,counter3,counter4)=40+tier2numcomparators(counter,counter2);
     end
    end
   end
  end
 end
end

And that's where it said "Attempt to reference field of non-structure array".

这就是所谓的“尝试引用非结构数组的域”。

1 个解决方案

#1


5  

TBH it sounds like maybe you've made a typo and put a . in somewhere? Otherwise please post the entire error as maybe it's happening in a different function or something.

TBH听起来好像你打错了,放错了。在某个地方吗?否则,请把整个错误都放到一个不同的函数中。

Either way you don't need all those for loops, it's simpler and usually quicker to do this (and should bypass your error):

不管怎样,你不需要所有的for循环,这样做更简单,而且通常更快(并且应该绕过你的错误):

First replicate your tier2numcomparators matrix so that it has the same dimension sizes as tier2comparatorconnectionpoints

首先复制tier2numcomparators矩阵,使其具有与tier2comparatorconnectionpoints相同的维度大小

T = repmat(tier2numcomparators + 40, 1, 1, size(tier2comparatorconnectionpoints, 3), size(tier2comparatorconnectionpoints, 4));

Now in one shot you can create a logical matrix of which elements meet your criteria:

现在,你可以一次创建一个符合你标准的逻辑矩阵:

ind = tier2comparatorconnectionpoints > T | tier2comparatorconnectionpoints < 60;

Finally employ logical indexing to set your desired elements:

最后使用逻辑索引来设置所需的元素:

tier2comparatorconnectionpoints(ind) = T(ind);

You can play around with bsxfun instead of repmat if this is slow or takes too much memory

如果这个过程很慢或者占用太多内存,你可以使用bsxfun而不是repmat

#1


5  

TBH it sounds like maybe you've made a typo and put a . in somewhere? Otherwise please post the entire error as maybe it's happening in a different function or something.

TBH听起来好像你打错了,放错了。在某个地方吗?否则,请把整个错误都放到一个不同的函数中。

Either way you don't need all those for loops, it's simpler and usually quicker to do this (and should bypass your error):

不管怎样,你不需要所有的for循环,这样做更简单,而且通常更快(并且应该绕过你的错误):

First replicate your tier2numcomparators matrix so that it has the same dimension sizes as tier2comparatorconnectionpoints

首先复制tier2numcomparators矩阵,使其具有与tier2comparatorconnectionpoints相同的维度大小

T = repmat(tier2numcomparators + 40, 1, 1, size(tier2comparatorconnectionpoints, 3), size(tier2comparatorconnectionpoints, 4));

Now in one shot you can create a logical matrix of which elements meet your criteria:

现在,你可以一次创建一个符合你标准的逻辑矩阵:

ind = tier2comparatorconnectionpoints > T | tier2comparatorconnectionpoints < 60;

Finally employ logical indexing to set your desired elements:

最后使用逻辑索引来设置所需的元素:

tier2comparatorconnectionpoints(ind) = T(ind);

You can play around with bsxfun instead of repmat if this is slow or takes too much memory

如果这个过程很慢或者占用太多内存,你可以使用bsxfun而不是repmat