find minima in 3D function/matrix

14 ビュー (過去 30 日間)
Joachim Schmid
Joachim Schmid 2015 年 3 月 18 日
編集済み: Mischa Kim 2015 年 3 月 18 日
I have data points (Z-values) of a area (-2:0.1:2) and would like to find the positions of both minima.
[X,Y]=meshgrid(-2:0.1:2);
Z=(X.*Y.*exp(-(X.^2)-(Y.^2))); % this is my 3D function
min(Z); % delivers a vector of the minimum in every column
MinV=min(min(Z)); % delivers the value we are looking for
find (Z==MinV); & gives two arguments
Q1: How to interpret the result of find? Q2: It is not the single (?) index of the element in the matrix, how can I get the indices?
(Sorry guys, I was looking for a solution but many problems are more complex.... and I am a beginner) Thany you for suggestions/help!

採用された回答

Mischa Kim
Mischa Kim 2015 年 3 月 18 日
編集済み: Mischa Kim 2015 年 3 月 18 日
Joachim, use instead
[r,c] = find(Z==MinV) % gives two arguments
r =
28
14
c =
14
28
which will also return two values each (the row and column numbers) since there seem to be two minima. The two values you receive with your code are the indices of the minima if you count through the rows and columns of the matrix
13*41 + 28 = 561
27*41 + 14 = 1121

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by