I am having some trouble using the load function in my code as I first use:
savepath='filepath';
savefile='Tumble Data User Applicable.mat';
save(fullfile(savepath,savefile),'ATtablef')
I use that code to save my table, ATtablef.
I then attempted to use:
PrevTable=load(savefile,'Data')
To create a variable with the loaded file.
When I ran the code I received this error:
Error using load
Unable to read file 'Tumble Data User Applicable.mat'. No such file or directory.
Any suggestions to correcting this error?

 채택된 답변

Star Strider
Star Strider 2020년 7월 7일

0 개 추천

I am surprised the save call worked at all!
Note that:
savepath='filepath';
savefile='Tumble Data User Applicable.mat';
ActualPathCreated = fullfile(savepath,savefile)
produces:
ActualPathCreated =
'filepath\Tumble Data User Applicable.mat'
Assuming that ‘filepath’ defines the path you want to use, remove the single quotes here:
savepath=filepath;
and it should work the way you intend it to work.

댓글 수: 7

Alexandra Philip
Alexandra Philip 2020년 7월 7일
I defined the path I wanted to use with the savepath. I just use 'filepath' as an example. I still need help with the load function though.
Star Strider
Star Strider 2020년 7월 7일
Be sure that you saved it to a path that is part of the MATLAB search path. MATLAB will not be able to find it otherwise.
I correctly matched the filepath to the MATLAB search path. However, when I create:
PrevTable=load(savefile)
The variable becomes a struct instead of a table. How could I correct this?
The variable becomes a struct instead of a table. How could I correct this?
You do not correct it. That is how load() is defined.
load() with no output assignment "poofs" variables into the workspace. You do not know which variables, and it can clobber variables you wanted to keep.
load() with an output assignment creates the output as a struct with one field for each variable. You can find out which entries were created by using fieldnames() .
You can then pull fields out of the struct, such as
loaded_data = load(savefile);
PrevTable = loaded_data.PrevTable;
Star Strider
Star Strider 2020년 7월 8일
Walter — Thank you!
Alexandra Philip
Alexandra Philip 2020년 7월 8일
Thank you! I was able to load it properly.
Star Strider
Star Strider 2020년 7월 8일
As always, our pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2020년 7월 7일

댓글:

2020년 7월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by