how does [~,I]=min(​abs(strain​-0.02)) work ?? (strain is a vector filled with floating point decimal numbers)

7 ビュー (過去 30 日間)
cant get a result from find command in this manner
y1=find (strain==min(abs(strain-0.02)))
but i was proposed to use the code in the question above could someone explain how it works??
  1 件のコメント
Karvelakis Anastasios-Petros
Karvelakis Anastasios-Petros 2017 年 1 月 14 日
As is suspected in the first place but nonetheless thank you very much for your assistance :)

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

採用された回答

John Chilleri
John Chilleri 2017 年 1 月 12 日
Hello,
Regarding your original question about:
[~,I] = min(abs(strain - 0.02))
Let's talk about what you're computing in the min() function before we discuss the function itself.
First, your vector strain has .02 subtracted from every element individually, then the absolute value of each element is taken. I'm guessing you already new this was going on, but just in case.
With respect to the min function, if you request two outputs, as you are above, min will return the minimum value and the index of that value. Let's say, for example, that abs(strain - .02) has a minimum value of .1 located in element 7 of your vector.
The min function would then return [.1, 7]. When you use the tilde (~), you are telling Matlab to not return this output; however, you are storing the index of the minimum in I.
_______________________________________________________
TLDR; I is the index of the minimum value in vector abs(strain - .02).
The documentation for min might prove useful if you're still confused.
Hope this helps!

その他の回答 (2 件)

Duong Hien Thuan
Duong Hien Thuan 2019 年 7 月 21 日
Dear Sir,
I would Matlab 7.8.0 (2009A) when I use this systax it is error "Expression or statement is incorrect--possibly
unbalanced (, {, or [.". So how can I fix this problem?
Thank you!
  1 件のコメント
Steven Lord
Steven Lord 2019 年 7 月 21 日
The ability to use the tilde (~) to ignore output arguments of a function call was introduced in release R2009b. Replace the tilde with a "dummy" variable name that indicates to you and to others reading your code that this output argument is not used.

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


Duong Hien Thuan
Duong Hien Thuan 2019 年 7 月 21 日
Thank Steven Lord so much!

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by