Need help using mink and maxk

조회 수: 18(최근 30일)
Conner Carriere
Conner Carriere 2021년 2월 8일
댓글: dpb 2021년 2월 9일
I am simplifying coordinates, MwCoords. The left column is the x values and the right column is y values. I do not want to alter the postition of the x or y values.
MwCoords =
241.5493 360.1065
241.7508 251.1975
246.9076 148.8279
350.6785 144.9718
349.2095 255.6598
352.6571 364.5513
456.4168 149.5675
459.3270 256.3704
460.4547 360.4354
I have been using mink to find the three minimum values in the x and maxk to find the 3 max values in the x
MwCoordsMins = mink(MwCoords(:,1),3)
MwCoordsMaxs = maxk(MwCoords(:,1),3)
This outputs
MwCoordsMins =
MwCoordsMaxs =
I need to put 1's in the mins, and 3's in the max of the origional MwCoords
From there I need to assign the 3 middle values to 2's
Then I need to plug it back into the origional matrix without disrupting the positioning of these. The postitioning will change every now and then, thats why it has to be in the same place.
After I figure out the x values, I move on to the y values.
If anyone can help, or offer insight that would be great!
Edit - Whatever I added, I put it in bold
  댓글 수: 2
Conner Carriere
Conner Carriere 2021년 2월 8일
I guess I am not sure how to return the outputs to their origional locations. It will be done repeatadly, so I will attempt to make a function out of it.

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

채택된 답변

Star Strider
Star Strider 2021년 2월 8일
편집: Star Strider 2021년 2월 8일
The mink and maxk functions can give the indices of those values as the second output.
If I understand correctly what you want to do, I would do something like this:
[MwCoordsMins,ix1] = mink(MwCoords(:,1),3);
[MwCoordsMaxs,ix2] = maxk(MwCoords(:,1),3);
Then assign the elements accordingly as ‘1’, ‘2’, or ‘3’.
EDIT — I originally posted the full answer before noticing that this was tagged as homework. That part is now gone.
  댓글 수: 9
dpb 2021년 2월 9일
NB: original had column 1 in all; now fixed above -- dpb

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

추가 답변(0개)


Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by