referencing arrays
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Sean de Wolski
am 5 Apr. 2012
action = {
['short']
['long']
['waiting']
['short']};
profit = {
[-50.00]
[100.00]
[0]
[20.00]};
results = profit(ismember(action,'short'))
0 Kommentare
Jan
am 5 Apr. 2012
action = {'short' 'long' 'waiting' 'short'};
result = profit(strcmp('short', action));
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!