Compare a vector values with martix having multiple rows
조회 수: 6 (최근 30일)
이전 댓글 표시
I want to compare a vector with a matrix having mutiple rows. Exact situation with coding and result described below:
For vector:
a vector of a single row and three columns shown below
coding c = []; c(end+1,:)=[k1 k2 k3]; disp (c);
result 2.4 2.5 3.9
For matrix:
coding b= []; b(end+1,:)=[Kp Ki k3 k4 k5]; disp(b);
result 1 1 2.9 2.7 3.6
1 2 3.5 3.9 3.9
................. so on.
Now, problem is:
Compare matrix column 3, 4 and 5 with a vector (2.4 2.5 3.9). Note, vector values are used as reference. In return, want a result of values in matrix that are equal and less than the values of vector.
In more detail: If any value of column 3 in matrix is equal or less than the 1st value vector then result display. But need a result that import complete row of this matrix. Similarly, if any value of column 4 in matrix is equal or less than the 2nd value vector then result display complete row of this matrix.
All these combinations displayed in a final matrix. Means final matrix contain all reults of import rows find after comparison.
댓글 수: 2
Walter Roberson
2022년 5월 20일
You would potentially have several results for matching column 3, a different number for matching column 4, and so on. Are all of these to go into the same output matrix, without any division between the sections ? Or when you say "display" do you mean to the command window, not storing in a matrix?
채택된 답변
David Hill
2022년 5월 20일
yourMatrix=[randi(2,20,2),5*rand(20,3)];
yourVector=5*rand(20,3);
newMatrix=yourMatrix(yourMatrix(:,3)<=yourVector(1)|yourMatrix(:,4)<=yourVector(2)...
|yourMatrix(:,5)<=yourVector(5),:);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!