array indices must be positive integers or logical values.

12 ビュー (過去 30 日間)
aarthy reddy R
aarthy reddy R 2019 年 10 月 14 日
コメント済み: aarthy reddy R 2019 年 10 月 14 日
i am getting this error
Array indices must be positive integers or logical values.
Error in tabular/dotParenReference (line 108)
b = b(rowIndices);
Error in tryout (line 12)
z1 = sum(y.resource (p:T).^2)
for the following lie of code
z1 = sum(y.resource (p:T).^2)
here i would be taking values from variable resource in table y, for which sum till end day of project(t) whose square is found.
i hope this explains the above line from code.
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 10 月 14 日
That suggests that p is not a positive integer.
aarthy reddy R
aarthy reddy R 2019 年 10 月 14 日
function[fitness_value] = tryout(x)
T = 18; %total number of days to complete project
oo = readtable ('datasheet.xlsx');
x1 = round(rand() );
p = bin2dec(num2str(x1))
x2 = round(rand() );
q = bin2dec(num2str(x2))
x3 = round(rand() );
r = bin2dec(num2str(x3))
z1 = sum(resource (p:T).^2)
z2 = sum(resource (q:18).^2)
z3 = sum(resource (r:18).^2)
A = [ z1 z2 z3 ];
fitness_value = max(A);
fitness_value = -1 * fitness_value;
end
this the code, here the value taken is binary so cannot be non positive
any suggestions please

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

採用された回答

John D'Errico
John D'Errico 2019 年 10 月 14 日
編集済み: John D'Errico 2019 年 10 月 14 日
p is sometimes zero. sometimes it is one. how you are creating p is a bit silly, as there is absolutely no reason to use bin2dec, and num2str is also a bit over the top. For example, I tried it twice, and I see:
>> x1 = round(rand() );
p = bin2dec(num2str(x1))
p =
1
>> x1 = round(rand() );
p = bin2dec(num2str(x1))
p =
0
But then you have the line:
z1 = sum(y.resource (p:T).^2)
if sometimes p is zero, then you create a vector p:T. Whenever p is zero, then p:T will be a vector that STARTS at zero.
When p is zero, can you use that vector as an index into the variable y.resource?
NO.
  1 件のコメント
aarthy reddy R
aarthy reddy R 2019 年 10 月 14 日
thank you so much your explanation is of great help
i have a doubt i have to choose different values for p but it must be less then 18
so i can do square of resources from that day till end
so i used rand funtion
can u provide any suggestions?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by