Array indices must be positive integers or logical values

5 ビュー (過去 30 日間)
Abhijit Bhandari
Abhijit Bhandari 2020 年 5 月 10 日
回答済み: Deepak Gupta 2020 年 5 月 10 日
x=0.05:0.05:1;
y=log(x)';
f(x)=x.*y;
[fMin,idx]=min(f);
result=x(idx);

回答 (1 件)

Deepak Gupta
Deepak Gupta 2020 年 5 月 10 日
Hi Abhijit,
Here you don't need to use index. I think you are trying to create a function of x with f(x), but as you have already defined absolute value of x, it is being taken as index and in matlab indices are positive integers. Your code will work without index for f.
x=0.05:0.05:1;
y=log(x)';
f=x.*y;
[fMin,idx]=min(f);
result=x(idx);
If you want to first create a function of x and then you need to first declare it using sym/syms. To know more about how to create symbolic functions follow this link: https://in.mathworks.com/help/symbolic/create-symbolic-functions.html
Cheers

カテゴリ

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