referencing arrays
조회 수: 1 (최근 30일)
이전 댓글 표시
I have 2 arrys that are the same size, I'd like to use the values from one array to reference values in the other.
Example
action =
['short']
['long']
['waiting']
['short']
profit =
[-50.00]
[100.00]
[0]
[20.00]
I'd like to take the profit values where action = 'short' and put them into a third array called results.
so results = [-50.00] [20.00]
what is the best way to do this?
댓글 수: 0
답변 (2개)
Sean de Wolski
2012년 4월 5일
action = {
['short']
['long']
['waiting']
['short']};
profit = {
[-50.00]
[100.00]
[0]
[20.00]};
results = profit(ismember(action,'short'))
댓글 수: 0
Jan
2012년 4월 5일
action = {'short' 'long' 'waiting' 'short'};
result = profit(strcmp('short', action));
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!