Load mat files located path into a function
163 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello!, I have a function output=function(input), where 'input' is a mat file that is saved on my path and to which I want to apply the operation defined by 'function'
So far, I haven't been able to make the function call the file from the path and have been force to load it into the workspace prior to calling the function.
For the function code itself I have:
[output]=function(input);
data=load(input);
The problem is that this kind of syntax loads the mat files as structured arrays and I need them to be load as the simple mat files they are.
I am new in Matlab so maybe I am probably just making a silly mistake so, I will greatly appreciate any assistance.
0 comentarios
Respuestas (4)
Jan
el 12 de Jun. de 2013
Editada: Jan
el 12 de Jun. de 2013
Please post the line, which causes the error. It is confusing that you use "input" as name of a variable and obviously as contents of this variable at the same time. In addition "input" is a built-in Matlab function.
I guess, the proble is related to the frequently occurring problems with the functional form of load():
load a
is equivalent to:
load('a')
but not to:
load(a)
Perhaps this helps:
FileName = 'input.mat';
FolderName = 'C:\Temp';
File = fullfile(FolderName, FileName);
load(File); % not: load('File')
I frequently suggest not to load variables directly to the workspace, because one can never know if a local variable is overwritten:
k = 10;
load('YourFile.mat');
disp(k)
Reading the source code cannot reveal the final value of k, because it depends on the contents of the MAT file. Therefore it is much saver to store the output in a struct. In addition this is faster also, because Matlab's JIT accelerator cannot be confused by dynamically redefined variables.
0 comentarios
Image Analyst
el 30 de Mayo de 2013
I would recommend explicitly putting the folder in there rather than have it search the path to find it, which can be a problem if there are two folders with that filename.
fullFileName = fullfile(folder, 'whatever.mat');
The mat file will load as one structure, not multiple. You can extract the individual variables
storedStructure = load(fullFileName);
myString = storedStructure.myString;
myDouble = storedStructure.myDouble;
Of course if you have a lot of them it makes your output argument list very long and I'd recommend just passing the whole structure back so that everything is contained in one convenient variable. In your calling routine you can then refer to the structure members (like on the right side of the lines above), or you can extract them into separate variables, like the lines above did.
1 comentario
Jonathan Sullivan
el 30 de Mayo de 2013
Not sure if I understand your problem, but it sounds like you want the data in your mat file loaded as variables in the workspace, not as fields of a structure. If so, just try replacing your load line with this (notice no output to the load command):
load(input);
4 comentarios
Iain
el 12 de Jun. de 2013
put a breakpoint immediately before and after the load(input) line, and look at the workspace of the function in both cases. I suspect that you will find there are new variables which are the variables you ought to be using.
Helen Victoria
el 14 de Dic. de 2018
hello all,
I am beginner in deep learning.I have downloaded CIFAR10 dataset which has 5 batch file and one test batch file.how to make this as image datastore input as training and testing data.kindly help.
0 comentarios
Ver también
Categorías
Más información sobre Large Files and Big Data en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!