Subscript indices must either be real positive integers or logicals. Error in erlang3 (line 4) erlang = lambda*exp​(-1*lambda​*xk)*(lamb​da*xk)^2/2​;

1 回表示 (過去 30 日間)
clc;
clear scr;
xk = rand(10000);
erlang = lambda*exp(-1*lambda*xk)*(lambda*xk)^2/2;
y = histogram(erlang,'Normalization','pdf');
subplot(2,1,1);
plot(xk,y);
% xlabel('X');
% ylabel ('Y');
title ('Erlang-3 Distribution');

回答 (3 件)

Robert
Robert 2016 年 3 月 28 日
Is there any chance you defined a variable exp before executing this code? My best guess (given the limited information provided) is that MATLAB is interpreting (-1*lambda*xk) as an indexing operation into the variable exp, which could happen if exp is not pointing to the function as you expect but is instead pointing to a variable.
  2 件のコメント
vanitha usika
vanitha usika 2016 年 3 月 28 日
exp is just define the exponential variable generally for exponential we don't need to define exp
Robert
Robert 2016 年 3 月 29 日
Exactly; however, there is nothing stopping you from replacing exp for example
clear
exp(1)
exp(2)
exp = 42
exp(1)
exp(2)
As Walter suggested, you can use the command which to ask MATLAB from where it is getting exp
clear
which exp
exp = 42
which exp

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


Star Strider
Star Strider 2016 年 3 月 28 日
The most likely possibility is that somewhere in your code you have a variable called ‘exp’. The solution is to find it and name it something else.

Walter Roberson
Walter Roberson 2016 年 3 月 28 日
At the command prompt command
dbstop if error
and run the code. When (if) it stops with the error, please report the results of
which exp

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by