Borrar filtros
Borrar filtros

can not load mat file correctly

1 visualización (últimos 30 días)
Sam
Sam el 31 de Jul. de 2012
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

Respuestas (2)

Ilham Hardy
Ilham Hardy el 31 de Jul. de 2012
Why not use load('test.mat','x')

Image Analyst
Image Analyst el 31 de Jul. de 2012
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

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by