Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Question about using elements of an array for computation

1 回表示 (過去 30 日間)
Sri
Sri 2014 年 9 月 18 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have given D0=rand(100,1) and also defined the other single column vectors m, n, r in similar way. The rest of the quantities are scalars. Now, (i runs from 1 to 100)
function [ D,Ni ] = constant_loading_1(D0,N0,Nc,R1,r,n,m,N)
%UNTITLED3 Summary of this function goes here
D=1-power(power(1-D0(i),n(i)+1)-((N-N0)/Nc)*(n(i)+1)*power((1-r(i)/R1),m(i)),1/(n(i)+1));
Ni=ceil(N0+((Nc/(n(i)+1))*(power(1-D0(i),n(i)+1))*(power(R1/(R1-r(i)),m(i)))));
end
is giving the error message: _Subscript indices must either be real positive integers or logicals.
Error in constant_loading_1 (line 3) D=1-power(power(1-D0(i),n(i)+1)-((N-N0)/Nc)*(n(i)+1)*power((1-r(i)/R1),m(i)),1/(n(i)+1));_

回答 (2 件)

Mischa Kim
Mischa Kim 2014 年 9 月 18 日
編集済み: Mischa Kim 2014 年 9 月 18 日
Sri, I believe what you want to do is
D = 1 - power(power(1-D0,n+1)-((N-N0)./Nc).*(n+1).*power((1-r./R1),m),1./(n+1));
Ni = ceil(N0+((Nc./(n+1)).*(power(1-D0,n+1)).*(power(R1./(R1-r),m))));
Note the dot operators that allow you to do element-wise operations on vectors (see e.g. http://www.mathworks.com/help/matlab/ref/times.html).

Sri
Sri 2014 年 9 月 18 日
function [ D,Ni ] = constant_loading_1(D0,N0,Nc,R1,r,n,m,N)
%UNTITLED3 Summary of this function goes here
D=1-power(power(1-D0,n+1)-((N-N0)./Nc).*(n+1).*power((1-r./R1),m),1./(n+1));
Ni=ceil(N0+((Nc/(n+1)).*(power(1-D0,n+1)).*(power(R1/(R1-r),m))));
end
gives
Error using .^ Matrix dimensions must agree.
Error in constant_loading_1 (line 4) Ni=ceil(N0+((Nc/(n+1)).*(power(1-D0,n+1)).*(power(R1/(R1-r),m))));
  2 件のコメント
Mischa Kim
Mischa Kim 2014 年 9 月 18 日
Please see updated answer above. There are some more dots missing in the equation for Ni.
Sri
Sri 2014 年 9 月 18 日
編集済み: Sri 2014 年 9 月 18 日
Thank you. I have tried that. It didn't work. so ended up introducing new variables. http://www.mathworks.in/matlabcentral/answers/155266-how-to-assign-an-element-of-a-column-array-to-a-variable

この質問は閉じられています。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by