0

I am trying to write a variable into a structure and read it from another existing structure:

struct1.vector = struct2.matrix(:,1);

when I run this line in my script it will create a double variable struct1. Thats why I will get the error:

Unable to perform assignment because dot indexing is not supported for variables of this type.

When I just run the same line in my Command Window it will create a struct variable struct1 just as I want to. Also there are multiple lines, where I try to write into struct1 and some times the first 4 lines work and the 5th doesn't. I don't understand why the script is creating a double, can anybody help me with this?

Help is much appreciated, thank you.

1

1 Answer 1

3

That probably means that you already have a variable named struct1 in your workspace, either leftover from some previous activity, or assigned earlier in the script.

You can make sure you have a fresh workspace by calling clear before running your script. Better yet, turn your script into a function, and it will have its own workspace.

You can also replace the whole struct1 variable with a new empty struct, to make sure it's of the right type, before assigning to its fields.

struct1 = struct;
struct1.vector = struct2.matrix(:,1);
Sign up to request clarification or add additional context in comments.

3 Comments

I just tried it, but the error remains. There is no other struct with the same name.
@downbydawn: That's not possible, please post a minimal reproducible example in your question so we can see what exactly you are doing.
I found a variable that was accidentally assigned the same way, changed it and it works now. Thank you!

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.