matlab下标错误的原因

学习 时间:2026-04-04 21:00:08 阅读:569
matlab下标错误的原因本人想生成一组标准正态分布的随机变量,并重复试验100次,并求出其均值和方差,matlab代码如下:for j = 1:100 a = randn(1,5); m(j) = mean(a); 运行到这一步时就出错了,错误原因如下:Subscript indices must either be real positive integers or logicals.但是我觉得下标都是正整数啊,大家帮我看看问题出在哪了?

最佳回答

义气的蓝天

端庄的白羊

2026-04-04 21:00:08

怀疑你在前面的代码中把mean当成变量使用了,建议clear mean试试:>> mean=1;>> for j = 1:100 a = randn(1,5); m(j) = mean(a); end? Subscript indices must either be real positive integers or logicals。>> clear mean>> for j = 1:100 a = randn(1,5); m(j) = mean(a); end>>

最新回答共有2条回答

  • 震动的仙人掌
    回复
    2026-04-04 21:00:08

    怀疑你在前面的代码中把mean当成变量使用了,建议clear mean试试:>> mean=1;>> for j = 1:100 a = randn(1,5); m(j) = mean(a); end? Subscript indices must either be real positive integers or logicals。>> clear mean>> for j = 1:100 a = randn(1,5); m(j) = mean(a); end>>

上一篇 深圳市的面积大约是2020公顷还是平方千米?

下一篇 实验室制备二氧化硫可以用亚硫酸钠和稀盐酸反应么