Compare a vector values with martix having multiple rows
5 次查看(过去 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!