How to run the same script but for different datafiles

21 ビュー (過去 30 日間)
Ivan Tadiwanashe Chuma
Ivan Tadiwanashe Chuma 2023 年 7 月 15 日
編集済み: John D'Errico 2023 年 7 月 15 日
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.

回答 (1 件)

John D'Errico
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.

カテゴリ

Help Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by