access struct data using 'fileName' given by U = load([filePath fileName])

3 visualizaciones (últimos 30 días)
Hi,
thanks in advance.
I load a mat file called, for example, bending0001.mat using:
%------------------
[fileName filePath] = uigetfile('*.mat', 'Select data file', '.');
if filePath==0, error('None selected!'); end
U = load([filePath fileName])
%------------------
I want to access the struct data without giving the file name, but using the U. That means:
  • this way :)
length_ = length(U.Trajectories.Labeled.Data(6,:,:));
  • not this way :(
length_ = length(bending0001.Trajectories.Labeled.Data(6,:,:));
what happens is that the higher struct field has the same name as the file, using this feature, I could open multiple files easier without typing the name at each access
thank you a lot,
Carolina
  2 comentarios
TAB
TAB el 29 de Mzo. de 2012
Variables from the U=load('bending0001.mat') function will be collected in U and not in bending0001.
Please check your question. It is not clear.
Carolina Brum Medeiros
Carolina Brum Medeiros el 5 de Abr. de 2012
I mean, instead of typing the name of the different files to access the struct, like this:
length_ = length(bending0001.Trajectories.Labeled.Data(6,:,:));
I search for an automatic way to load the file name in the space ?? below,
length_ = length(??.Trajectories.Labeled.Data(6,:,:));
This way, I can load various files without editing my script each time I'm loading a different .mat struct file.
Thanks for your answer, I didn't receive the notice that someone answered it. Thanks

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 5 de Abr. de 2012
Doesn't the already posted U=load() solve the problem sufficiently?
  1 comentario
Carolina Brum Medeiros
Carolina Brum Medeiros el 5 de Abr. de 2012
Thanks for your answer. And the answer for your question is: no.
note the piece of code below:
[fileName filePath] = uigetfile('*.mat', 'Select data file', '.');
% here I select bending0001.mat, for example
if filePath==0, error('None selected!'); end
load( fullfile(filePath, fileName))
>> Analog_SG_full = fileName.Analog.Data(1,:);
answer:
??? Attempt to reference field of non-structure array.
As I access different field in the struct data a lot of times along the script, I don't want to change the file name on each one of them. Clearly, the product from load() is not compatible for the struct path.
Thanks,
Carolina

Iniciar sesión para comentar.

Categorías

Más información sobre Structures 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