0
votes

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
hello and welcome to stackoverflow. please see stackoverflow.com/help/minimal-reproducible-example - Prany

1 Answers

2
votes

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);