下面的matlab的代码出现这个错误:Array indices must either be real positive integers logicals character arrays or strings如何改正a = 526 519 421 400 295 274 246 190 064 127; 190 099 190 113 127 225 148 204 309 351;
在这段代码中,出现了错误的原因是在索引cum11 = sum(y([31 21]));和cum12 = sum(y([32 22]));中使用了非整数索引。在MATLAB中,数组的索引必须是实数正整数、逻辑索引、字符数组或字符串。
要修复这个错误,您可以将非整数索引改为整数索引。根据您的代码逻辑,可能是因为数字31和32应该被替换为数字30和31。因此,您可以将这两行代码修改为以下内容:
cum11 = sum(y([30 21]));
con(16) = cum11*154 <= 12500;
cum12 = sum(y([31 22]));
con(17) = cum12*154 <= 11000;
然后,重新运行代码,应该就不会再出现相同的错误了。
原文地址: http://www.cveoy.top/t/topic/iNt1 著作权归作者所有。请勿转载和采集!