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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by