How to write a changing table name in setdiff function?
Show older comments
Hello,
I would like to know how to write a function inside which there is a changing table name.
I have created a table which will change at each loop
eval(['Port' num2str(i-1) '= Portfolio'])
At some point I need to make a difference between this table and a new portfolio so i used the function setdiff
for example, there is a Port1 which is created, now I need to execute this :
[i,j] = setdiff(Port1(:,2), Portfolio(:,2))
Port1 is created by the eval function. Can you tell me how I can incorporate the name of the table dynamically inside the setdiff function which will pick up automatically the newly created table ( port2, port3....). I tried this but its not working :
[i,j] = setdiff(['Port' num2str(i-1)](:,2),Portfolio(:,2))
Thank you very much for your help
D
1 Comment
@Davin: it is almost always a bad idea to create variable dynamically. Read this to know why:
Much simpler and more reliable is to use indexing. You can easily put the tables into cell arrays, and using indexing is then trivial.
Accepted Answer
More Answers (0)
Categories
Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!