gpt4 book ai didi

matlab - 为什么我收到错误 "Index exceeds matrix dimensions"?

转载 作者:太空宇宙 更新时间:2023-11-03 20:23:19 25 4
gpt4 key购买 nike

我目前是 MATLAB 的新手。我的代码如下。我只是有一个问题,为什么我总是收到所提供函数的错误“索引超出矩阵维度”:

a = [105 97 245 163 207 134 218 199 160 196 221 154 228 131 180 178 157 151 ...
175 201 183 153 174 154 190 76 101 142 149 200 186 174 199 115 193 167 ...
171 163 87 176 121 120 181 160 194 184 165 145 160 150 181 168 158 208 ...
133 135 172 171 237 170 180 167 176 158 156 229 158 148 150 118 143 141 ...
110 133 123 146 169 158 135 149];

mean = mean(a)
std = std(a)
max = max(a)
min = min(a)
range = range(a)

最佳答案

不要为变量赋予与现有函数相同的名称。这shadows the function .当您随后尝试使用参数调用该函数时,您最终会得到 indexing。带有参数的变量,在本例中尝试索引变量中不存在的元素,因此出现错误。

使用clear删除现有变量,然后使用新变量名称重新运行计算:

clear mean std max min range;
meanResult = mean(a);
stdResult = std(a);
...

关于matlab - 为什么我收到错误 "Index exceeds matrix dimensions"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47802940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com