0

I'm very new to Matlab and maybe a very basic question, but I need help:

I have a path:

file = C:\this\is\path\to\my_file.mat

This is a file which contains nested structure and I need just to access one variable. In my script, first I need to get the file name which I will use as variable later:

[pathstr,name,ext] = fileparts(file);

So, now I have the variable name with the content my_file.mat

S = load(file)

value = S.('name').structA.SubstructA1.variableA

Matlab is generating the message:

"Reference to non-existent field 'name'."

So, how is the correct way to use the variable in this case ?

JohnDoe
  • 825
  • 1
  • 13
  • 31
  • 1
    Start with a blank workspace (using `clear`) then do `file = 'C\...'` and `load(file)`. Whatever variables you saved in `my_file.mat` will now be in your workspace, no assigning to new variables needed. Of course you don't always have to start with a blank workspace, but it makes this example clear. – Wolfie Jul 12 '17 at 13:12

1 Answers1

1

You are very close, just remove the single quotes from around the variable, name, like this:

value = S.(name).structA.SubstructA1.variableA
acampb311
  • 333
  • 4
  • 11