Assigning an arbitrary number to an array

조회 수: 2 (최근 30일)
Joseph McGorry
Joseph McGorry 2021년 8월 20일
댓글: Joseph McGorry 2021년 8월 20일
My code is
x = [2.32, 4.23, 1.92, 3.24, 2.13];
points = [3, 1, 2];
first_answer = x(points);
second_answer = min(first_answer);
third_answer =
the first_answer gives 1.92, 2.32, 4.23 the second_answer gives 1.92 and i need the first answer to give me the value 3 which is the smallest x-value, not it's position of X which is 1 but the number it is assigned to which is 3. I do not know what code I need to achieve this. Thanks in advance for any help thanks
  댓글 수: 1
Stephen23
Stephen23 2021년 8월 20일
편집: Stephen23 2021년 8월 20일
"...i need the first answer to give me the value 3 which is the smallest x-value"
Do you actually mean the third answer? It seems that you are asking about the third answer, not the first answer.

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

채택된 답변

Stephen23
Stephen23 2021년 8월 20일
x = [2.32, 4.23, 1.92, 3.24, 2.13];
points = [3, 1, 2];
first_answer = x(points);
[second_answer,idx] = min(first_answer);
third_answer = points(idx)
third_answer = 3
  댓글 수: 1
Joseph McGorry
Joseph McGorry 2021년 8월 20일
Thank you very much this is what I was after

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by