How to load data from a location other than current directory
50 次查看(过去 30 天)
显示 更早的评论
I would like to be able to load a .mat file from an arbitrary location that is not my currently selected folder.
Example: data is stored in C:\users\me\Documents\MATLAB\data\example_data.mat
current selected folder (where script is running) is C:\users\me\Documents\MATLAB\projects\project1\example_code.m
What code could I use to load example_data.mat in a some script (example_code.m) running from any arbitrary folder in MATLAB?
Thanks!
0 个评论
采纳的回答
Azzi Abdelmalek
2015-7-13
编辑:Azzi Abdelmalek
2015-7-13
data=load('C:\users\me\Documents\MATLAB\data\example_data.mat')
data is a struct variable, for example:
data=
a: [1 2 3]
b: [2 3 4]
c: [3 4 5]
The you can access all your variables
a=data.a
b=data.b
c=data.c
2 个评论
Azzi Abdelmalek
2015-7-13
编辑:Azzi Abdelmalek
2015-7-13
If you want to assign values to each variable automatically:
filename='C:\users\me\Documents\MATLAB\data\example_data.mat'
str=whos('-file',filename)
str={str.name}
load(filename,str{:})
更多回答(1 个)
PAVANRAJ PRAJJU
2022-5-15
What is the command that is used to call data from a file which is saved in the same directory
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!