Loop on changing databases

조회 수: 1(최근 30일)
Alexandra 2015년 7월 2일
댓글: Alexandra 2015년 7월 6일
We run a code where part of it depends on variables we import from excel.
We want to run a loop on the code for it to run 20 times importing the variable from different excel files to create scenarios. Each scenario has to be saved automatically. The name of the variables never change.
Can we do this?
Thank you very much


Abhiram Bhanuprakash
Abhiram Bhanuprakash 2015년 7월 6일
Hi Alexandra,
Yes you can do this using xlsread to read from different Excel files. The structure of the code would look like this:
excelFilenamesCellArray = {Array of Excel file names/paths as strings};
for i=1:20
[num,txt,raw] = xlsread(excelFilenamesCellArray{i});
%Create scenario
%Save as separate file using (may be) xlswrite?
I'm not sure what you mean by 'scenario', so the above code is not complete. You can modify it as per your requirement.
Doc for xlsread and xlswrite are at:
Hope this helps,
  댓글 수: 3
Alexandra 2015년 7월 6일
Hi Abhiram, it helps. Thanks a lot. I did manage the xlsread but it doesn't insert the variables in the workspace, so the next lines of code don't recognize the variables.

댓글을 달려면 로그인하십시오.


Community Treasure Hunt

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

Start Hunting!

Translated by