Indexing to table subset from unique

1 visualizzazione (ultimi 30 giorni)
dpb
dpb il 17 Mag 2020
Commentato: dpb il 20 Mag 2020
Have a fairly complex table that contains, amongst other things, a Formula field (altho what the field is is immaterial to the question, just for specifics to talk about) that, in part, looks like...
>> tS62671=tShow(tShow.Acct=='S62671',:)
tS62671 =
75×12 table
Date Acct Corpus Realized Unrealized Value Formula Gift GiftDate Donor Note Comments
_____ ______ _________ ________ __________ _________ _________________________ ____________ ______________ ____________ ____________ ____________
Mar13 S62671 200000.00 0.00 0.00 200000.00 {'=185943.12+14056.88' } {2×1 double} {2×1 datetime} {2×1 string} {2×1 string} {2×4 string}
Apr13 S62671 200000.00 0.33 0.00 200000.33 {'200000' } {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
May13 S62671 200000.00 -871.33 -1625.31 197503.36 {'200000' } {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
Jun13 S62671 200000.00 -435.81 -3994.75 195569.44 {'200000' } {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
Jun14 S62671 200000.00 8609.48 -9999.63 198609.85 {'200000' } {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
Jul14 S62671 200200.00 10080.07 -12645.56 197634.51 {'=200000+200' } {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
...
Aug14 S62671 200200.00 11374.44 -12116.10 199458.34 {'=200000+200' } {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
Sep14 S62671 211645.04 13268.32 -14577.51 210335.85 {'=200200+11445.04' } {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
Oct14 S62671 219145.04 14879.44 -15271.01 218753.47 {'=200200+11445.04+7500'} {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
...
Mar15 S62671 219145.04 22978.06 -19844.04 222279.06 {'=200200+11445.04+7500'} {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
Apr15 S62671 249145.04 24888.67 -22428.68 251605.03 {'=219145.04+30000' } {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
May15 S62671 249145.04 26977.14 -24702.08 251420.10 {'249145.04' } {0×0 double} {0×0 double } {0×0 double} {0×0 double} {0×0 double}
Jun15 S62671 200000.00 29059.97 -28400.44 200659.53 {'=249145.04-49145.04' } {4×1 double} {4×1 datetime} {4×1 string} {4×1 string} {4×4 string}
Jul15 S62671 200000.00 30926.96 -29425.22 201501.74 {'=249145.04-49145.04' } {2×1 double} {2×1 datetime} {2×1 string} {2×1 string} {2×4 string}
Aug15 S62671 200100.00 32806.59 -31009.28 201897.31 {'=200000+100' } {2×1 double} {2×1 datetime} {2×1 string} {2×1 string} {2×4 string}
...
Underneath this if have
fnAddn=(@(s) find(contains(s,{'='}) & contains(s,{'+'}))); % only formula rows with additions
fnSubn=(@(s) find(contains(s,{'='}) & contains(s,{'-'}))); % only formula rows with withdrawals
What I need is then the first month for each unique addition/withdrawal entry --
[uf,ia]=unique(tS62671(fnAddn(tS62671.Formula),'Formula'));
which leads to the question -- is there a way to dereference the original table to return the unique rows in tS62671 other than by creating a temporary table first before the unique operation?
  3 Commenti
Asvin Kumar
Asvin Kumar il 20 Mag 2020
Just out of curiosity,
"It's not terrible to save the indexing variable first instead of wrapping the subset operation into the reference..."
You found the indexing variable 'ia' in the first place by wrapping the subset operations within the unique function call. Would your workaround still hold if you didn't have the 'ia'? You won't be able to meaningfully call unique on 'ixAdd'. Looks like we are still dependent on indexing a part of the original table to pass as input to unique.
dpb
dpb il 20 Mag 2020
Yeah, that's the problem...you lose the reference to the original otherwise...being unable to dereference a function expression syntactically. I think Octave has some facilities along that line but not sure can do this and don't have install to test.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by