フィルターのクリア

How can I know what element a value came from in a vector?

1 回表示 (過去 30 日間)
Roland
Roland 2011 年 2 月 22 日
I just started using Matlab. I found my minimum value of a given vector, but I need to know what the corresponding value is in another vector. Is there a way to know where the exact element is?
I need to know my "r" value for the cheapest.
v=600;
r=[1:.1:100];
h=(v-2.*pi.*((r.^3)./3))./(pi.*r.^2);
cost=(400.*(2.*pi.*r.*h))+(600.*(2.*pi.*r.^2));
cheapest=min(cost)
cheapest =
1.4825e+005

採用された回答

Walter Roberson
Walter Roberson 2011 年 2 月 22 日
[cheapest, cheapidx] = min(cost);

その他の回答 (2 件)

Oleg Komarov
Oleg Komarov 2011 年 2 月 22 日
Use the second output of min:
[cheapest, pos] = min(cost);
r(pos)
Oleg

Paulo Silva
Paulo Silva 2011 年 2 月 22 日
v=600;
r=[1:.1:100];
h=(v-2.*pi.*((r.^3)./3))./(pi.*r.^2);
cost=(400.*(2.*pi.*r.*h))+(600.*(2.*pi.*r.^2));
cheapest=min(cost);
Minr=r(cost==cheapest) %The r value that minimizes the cost function
%check if the value is correct on a figure
clf
hold on
plot(r,cost) %draw the cost function
plot(Minr,cheapest,'rx') %mark the minimum value
axis([0 10 0 5e5])
grid on

カテゴリ

Help Center および File ExchangeExternal Language Interfaces についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by