MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] matlab菜鸟问题 (https://www.labfans.com/bbs/showthread.php?t=13881)

cfyangyang 2011-09-11 18:10

matlab菜鸟问题
 
初学,编了一小段,就…………

a=[0 1 0 0 1 0 0 1
1 0 1 0 0 0 0 1
0 1 0 1 0 1 0 0
0 0 1 0 1 0 1 0
1 0 0 1 0 1 0 0
0 0 1 0 1 0 1 0
0 0 0 1 0 1 0 1
1 1 0 0 0 0 1 0]
s(1,8) %建个1*8的数组
for i=1:5 %嵌套循环
b=a^i
for j=1:8
s(j)=s(j)+b(j,j)/factorial(j)
end
end

错误是Index exceeds matrix dimensions.
觉得没越界啊,请高手们赐教

cfyangyang 2011-09-11 18:17

回复: matlab菜鸟问题
 
在线等啊,O(∩_∩)O谢谢

loalive 2011-10-11 13:22

回复: matlab菜鸟问题
 
我运行过你这个程序,没有发现你所说的问题,只是“s(1,8) %建个1*8的数组”这句产生错误。
我觉得,在建立s的时候,可以这样写:s=ones(1,8)

Matsun 2011-10-13 09:15

回复: matlab菜鸟问题
 
我也是新手啊,s建的是不是有问题??

学步者 2011-10-19 09:00

回复: matlab菜鸟问题
 
[QUOTE=cfyangyang;48228]初学,编了一小段,就…………

a=[0 1 0 0 1 0 0 1
1 0 1 0 0 0 0 1
0 1 0 1 0 1 0 0
0 0 1 0 1 0 1 0
1 0 0 1 0 1 0 0
0 0 1 0 1 0 1 0
0 0 0 1 0 1 0 1
1 1 0 0 0 0 1 0]
s(1,8) %建个1*8的数组
for i=1:5 %嵌套循环
b=a^i
for j=1:8
s(j)=s(j)+b(j,j)/factorial(j)
end
end

错误是Index exceeds matrix dimensions.
觉得没越界啊,请高手们赐教[/QUOTE]
s(1,8)不是建立一个数组,而是调用数组中的某个元素,
想要建立一个数组,最常用的就是
s=zeros(1,8)

赖明婵 2011-11-30 13:23

回复: matlab菜鸟问题
 
我也是个新手,我想问一下怎么运行下面的程序啊:
x=[113.2 155.2 192.8 233.2 300.3]
y=[1164701 1306936 1261643 1581008 1887837]
x=[ones(5),x]'
[b,bint,r,rint,stats]=regress(y,x)
为什么我运行出来都有错误,都是说All matrices on a row in the bracketed expression must have the
same number of rows.

赖明婵 2011-11-30 13:24

回复: matlab菜鸟问题
 
很着急的,能帮帮忙吗???


所有时间均为北京时间。现在的时间是 03:09

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.