Only read data once (with xlsread)

조회 수: 7 (최근 30일)
Christian
Christian 2015년 5월 3일
댓글: Christian 2015년 5월 4일
Hi there,
I am using xlsread to import data from Excel. This takes quite some time, but that's ok. The real problem is that Matlab loads the data whenever I run the script. Hence, whenever I change a few variables and run the whole script, I have to wait minutes because matlab is working on re-loading the data using xlsread.
Is there any way to only load the data ONCE and not every time I run the whole script?
Any help is much appreciated. Thank you very much.
Best Christian

채택된 답변

Star Strider
Star Strider 2015년 5월 3일
If the Excel file never changes, one option is to save the data in it as a .mat file. Those are smaller to store and faster to load.
Another option is to create your script as a function and store your Excel file as a persistent variable, then calling your function from a new external script file. Running it as a function instead of a script has disadvantages as well, so consider those and decide if that is an acceptable tradeoff for loading your Excel file each time.
  댓글 수: 6
Christian
Christian 2015년 5월 3일
Wow, works like a charm! :-) Star Strider, you just reduced the data loading time from 5 minutes to 45 seconds :-)) Thank you very much!
Star Strider
Star Strider 2015년 5월 3일
My pleasure!
The .mat files are binary files, so they’re smaller that other file types with the same information, and also load variables into your workspace faster than text or other format files.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 5월 3일
Yes. You can make a GUI with two buttons and a few other controls to change variables (input parameters). One button will run a function that loads the data. Then the other one will get the various settings of your input parameters and run the analysis code.
Here is a good framework to get you started: MAGIC
Also go over the Mathworks video tutorial on using GUIDE: http://blogs.mathworks.com/videos/category/gui-or-guide/
  댓글 수: 6
Image Analyst
Image Analyst 2015년 5월 3일
Glad my/our mat file suggestion (3 comments up) worked for you. Though you can only Accept one, perhaps you could also "Vote" for my answer too.
Christian
Christian 2015년 5월 4일
Couldn't have done it without you, Image Analyst :-) I'm fascinated by Matlab and it's incredibly vibrant forum. It took you guys 10 minutes to solve my problem. A problem, I've been struggling with for days!
Thanks again for your help, really appreciate it!

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

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by