필터 지우기
필터 지우기

From three vectors obtain the complete Vector that has the largest element, than the other two.

조회 수: 1 (최근 30일)
Hello Goodnight.
I have 3 vectors that will constantly be changing the value of their elements. But the vector with the element greater than the elements of the other two vectors will be chosen. For example, of these three vectors the vector C would be chosen, since it has as element 18 and is the largest of the elements of the three vectors. The complete vector C will be chosen
A = [12 3 4 5 6]; B = [3 15 7 6 4]; C = [9 1 18 2 7];
In another combination it could be vector A or B depends on the maximum value of its elements.
How do I select the complete vector that contains at least one greater element than the other two?
Greetings and thanks.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2018년 4월 4일
편집: Andrei Bobrov 2018년 4월 4일
A=[12 3 4 5 6];
B=[ 3 15 7 6 4];
C=[ 9 1 18 2 7];
R = [A(:);B(:);C(:)];
n = numel(A);
ii = ceil((1:3*n)/n);
[~,i1] = max(R);
out = R(ii == ii(i1));
or just
R = [A(:),B(:),C(:)];
[~,ii] = max(max(R));
out = R(:,ii);

추가 답변 (1개)

Tarsem Singh Khalsa
Tarsem Singh Khalsa 2018년 4월 4일
If you can combine the three vectors in a single matrix R (say), you can find the max value of the matrix and then find which row it belongs to.
Max_value = max(max(R)) % to find max value
[Row_Id,Clmn_Id] = find(R==Max_Value)
Row_Id and Clmn_Id will give you the position of the value in matrix
  댓글 수: 1
Ricardo Gutierrez
Ricardo Gutierrez 2018년 4월 4일
I made you suggest me: clc; clear; close all; format short
A=[12 3 4 5 6]; B=[ 3 15 7 6 4]; C=[ 9 1 18 2 7];
R = [A',B',C'] Max_value = max(max®) % to find max value [Row_Id,Clmn_Id] = find(R==Max_Value) . And this was the answer: Max_value = 18 Undefined function or variable 'Max_Value'. Error in Practica (line 9) [Row_Id,Clmn_Id] = find(R==Max_Value)
I wrote the wrong code?? Greetings.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by