필터 지우기
필터 지우기

referencing arrays

조회 수: 3 (최근 30일)
Trader
Trader 2012년 4월 5일
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?

답변 (2개)

Sean de Wolski
Sean de Wolski 2012년 4월 5일
action = {
['short']
['long']
['waiting']
['short']};
profit = {
[-50.00]
[100.00]
[0]
[20.00]};
results = profit(ismember(action,'short'))

Jan
Jan 2012년 4월 5일
action = {'short' 'long' 'waiting' 'short'};
result = profit(strcmp('short', action));
  댓글 수: 2
Trader
Trader 2012년 4월 6일
Jan - when I run your code i get a 0x0 cell. There is definitely data in the profits column and 'short' in my action array. Both action and profit are cell arrays, would this make a difference? Do I need cell2mat before doing all of this?
Trader
Trader 2012년 4월 6일
profit: [455x1 double]
action: {455x1 cell}

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

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by