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 ?

1
  • 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. Commented Jul 12, 2017 at 13:12

1 Answer 1

1

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

value = S.(name).structA.SubstructA1.variableA
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.