How to run the same script but for different datafiles
8 次查看(过去 30 天)
显示 更早的评论
I want to run a same live script but on different datasets of the same format. I have 10 different datasets in the same format. I am using a script from Bootstrap Using Chain Ladder Method - MATLAB & Simulink (mathworks.com). I can run the script on each dataset to obtain the results. However I want to load all the 10 datasets at once and automate the process such that I run the code once and get an output with a set of 10 outputs. I am kindly requesting for assistance.
0 个评论
回答(1 个)
John D'Errico
2023-7-15
编辑:John D'Errico
2023-7-15
Don't write scripts. Learn to write FUNCTIONS instead.
Your function will take, as input, the NAME of the data file it wants to process. It will then do the task, and return as a result any information you want it to return and save. Store that result in a variable, possibly a matrix, a vector, a cell array or a struct as appropriate.
Now just call your function 10 times, once for each data file.
Again, all of this hinges on your learning to use MATLAB as it is designed to be used. As an alternative, suppose MATLAB had NO functions at all? That is, suppose mean, sum, even the most basic functions, were themselves just scripts. In order to use them, you would need to define a variable with a SPECIFIC name in advance. They would run, and possibly step on any variables in your workspace, and create many more that you would not use or want. A MATLAB without functions would be a useless, terribly poor language. But by not learning to use functions of your own, to write your own functions, you limit what you can do, and that limit is a terribly constraining one.
So learn to use MATLAB. That is how you will solve your problem here. Learn to write functions. Your code will be far better for it.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Manage Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!