Subscript indices must either be real positive integers or logicals.

2 ビュー (過去 30 日間)
Yintong Zheng
Yintong Zheng 2016 年 2 月 27 日
回答済み: Image Analyst 2016 年 2 月 27 日
function T=baryeval2(tau,s,c,belta,x)
u=zeros(size(x))
d=zeros(size(x))
T=zeros(size(x))
for k=1:5
u=u+s(k).*belta(k).*(x-tau(k)).^(-1);
d=d+c(k).*belta(k).*(x-tau(k)).^(-1);
end
T=u./d;
end
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 2 月 27 日
You can copy and paste your code instead of inserting an image.

サインインしてコメントする。

回答 (4 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 2 月 27 日
編集済み: Azzi Abdelmalek 2016 年 2 月 27 日
You cant use an index equal to zero, Matlab allows only positive integer indices, or logical indices
  4 件のコメント
Yintong Zheng
Yintong Zheng 2016 年 2 月 27 日
I changed my code and now I get answers. But apparently something is wrong! Please help me to fix it.
Yintong Zheng
Yintong Zheng 2016 年 2 月 27 日
I insert all the values of tau, s, c, belta at command window. And all those '-Inf' are what I got.

サインインしてコメントする。


the cyclist
the cyclist 2016 年 2 月 27 日
MATLAB has 1-based indexing. When you enter
tau(k)
for k = 0, there is no such element.

Walter Roberson
Walter Roberson 2016 年 2 月 27 日
You have, in part, (x-tau(k)).^(-1) . If there is any x equal to tau(k) then the subtraction would give 0 and raising that to power -1 would give infinity. Infinity times any non-zero value gives infinity (infinity times 0 gives nan), so you would be adding infinity to the value, resulting in infinity. And then since you are effectively totaling values, you are going to get an infinite result.
  2 件のコメント
Yintong Zheng
Yintong Zheng 2016 年 2 月 27 日
can you advice me how to fix this?
Walter Roberson
Walter Roberson 2016 年 2 月 27 日
If you do have an x equal to some tau, then inf or nan is the correct answer for the formulae you have written. The situation is exactly like asking to total 1/x when x is allowed to be 0.

サインインしてコメントする。


Image Analyst
Image Analyst 2016 年 2 月 27 日

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by