Find the Argmin of a vector

11 ビュー (過去 30 日間)
Mohsen Dlala
Mohsen Dlala 2020 年 8 月 8 日
コメント済み: Matt J 2020 年 8 月 10 日
Help:
Let x be a vector and B_1...B_p p matrices,
I look for the index j* of the matrix such that
||B_j*||=min ||B_i x||, (||.||=norm)
How do I write this with matlab?
  5 件のコメント
Mohsen Dlala
Mohsen Dlala 2020 年 8 月 8 日
@Walter Roberson
As I'm a beginner in Matlab, I didn't understand anything, anyway, thank you very much for your answer.
Walter Roberson
Walter Roberson 2020 年 8 月 8 日
You have variables named B_ followed by a number, and you want to process the whole series of variables. That is bad programming practice. You should have avoided naming the variables that way, and should have used (for example) a cell array.
Are you trying to find which of the B_ arrays leads to the smallest norm given a vector x? If so then if you had the arrays represented as a cell array, that would only be a small number of statements.

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

採用された回答

Matt J
Matt J 2020 年 8 月 8 日
編集済み: Matt J 2020 年 8 月 9 日
You should have avoided naming the variables that way, and should have used (for example) a cell array.
Indeed. Here's an example of how to do it when that is the case.
Bcell={rand(5), rand(5), rand(5), rand(5)}; %B1,...,Bp p=4
[~, jstar] = min(cellfun(@(B) norm(B*x),Bcell)) %EDITED
  5 件のコメント
Mohsen Dlala
Mohsen Dlala 2020 年 8 月 9 日
Thanks very mach Matt
Matt J
Matt J 2020 年 8 月 10 日
You're very welcome, but please Accept-click the answer if you got it working.

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

その他の回答 (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