How to do this in MATLAB without for loops
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I have 4 vectors x1, x2, x3, and x4 all of size N-by-1. I need to select two vectors such that their minimum values are the maximum among all. How can I do that in MATLAB without using for loops?
Thanks
댓글 수: 0
답변 (2개)
Daniel Shub
2012년 3월 12일
What about using an Nx4 matrix (or a cell array) instead of x1, x2, ...
In general x1, x2, ... naming is a bad idea:
댓글 수: 0
Andrei Bobrov
2012년 3월 12일
EDIT
n = 4;
a = eval(['[',sprintf('x%d,',1:n),']']);
[~,idx] = sort(min(a),'descend');
out = a(:,idx(1:2))
댓글 수: 4
Jan
2012년 3월 13일
There is even no general case of x1, x2, x3, ... as long as Matlab cannot handle x_inf.
I think I should publish a Mex function "Unpoof('x', a, b)", which concatenates the contents of the variables x<a> to x<b> to the variable x and use the ASSIGNIN equivalent to put x into the caller workspace.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!