필터 지우기
필터 지우기

Can anyone help me?

조회 수: 2 (최근 30일)
William Grant
William Grant 2020년 4월 13일
댓글: Ameer Hamza 2020년 4월 13일
Hi,
I have two matrixes/vectors or whatever you want to call them.
g = [3;4;5;6;] %Row Indexes 3 4 7 and 8 of items
h = [511;818;379;812] %Prices
I want them to some how be merged together and I want to be able to call their index to represent a number. Say I want Product 3 and I want to know the price is 511, or product 5 which is 379.
Is there a way to link these two together, so for say in pseudocode whether it's correct pseudo or not.
if 5 is selected then display 379 or
if price 379 is selected display row 5.
If anyone could help me, I'd be eternally grateful.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 13일
편집: Ameer Hamza 2020년 4월 13일
This anonymous function will work
g = [3;4;5;6;]; %Row Indexes 3 4 7 and 8 of items
h = [511;818;379;812]; %Prices
fun = @(x) h(g==x);
Result
>> fun(3)
ans =
511
>> fun(5)
ans =
379
>> fun(6)
ans =
812
  댓글 수: 2
William Grant
William Grant 2020년 4월 13일
Thanks mate, that's amazing.
Ameer Hamza
Ameer Hamza 2020년 4월 13일
Glad to be of help.

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

추가 답변 (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