can not load mat file correctly
2 次查看(过去 30 天)
显示 更早的评论
How to make the function load_dataset below return x value of 2 ?
Thanks
S
>>clear all;
>>x=2;y=4;
>>save('test.mat');
>>x = load_dataset('test.mat','x');
>>x
x =
x
----
function dataset = load_dataset(cfmat,dataset)
try
load(cfmat,deblank(dataset));
catch
dataset=[];
end
0 个评论
回答(2 个)
Image Analyst
2012-7-31
Try something like this (untested):
function storedDataset = load_dataset(cfmat, dataset)
try
storedStructure = load(cfmat);
% Check to see if the requested field exists in the structure.
tf = isfield(storedStructure, dataset)
if tf
% The field exists. Use dynamic fieldname to extract it.
storedDataset = storedStructure.(dataset);
else
storedDataset = [];
end
catch ME
warningMessage = sprintf('%s\n', ME.message);
fprintf('%s\n', warningMessage);
uiwait(warndlg(warningMessage));
storedDataset =[];
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!