0

I have 5 different structure and I want to calculate some variables for all of them. To do that, I wrote the following code:

for i=1:5
[StructureI(i), ReqTab(i), jt(i), B(i)]=Checkall(E);
end

The values StructureI, ReqTab, jt and B are calculated in another function and they are

StructureI= 1X4 matrix,
ReqTab= 4X2 matrix,
jt=2x1 matrix,
B=4x4 matrix

When I run the code it calculates all the varibles in the function Checkall. However, when it turns to the parent code, it gives and error "Conversion to double from struct is not possible."

How can I solve this problem?

Thanks in advance.

1
  • The structures that you mention contain just one matrix each. Why are you using structures at all then? Couldn't you just return StructureI as a 2D matrix and then use a third dimension to store the dirrefernt results in each loop? (same for the other 3 vars) Commented Aug 8, 2016 at 11:42

1 Answer 1

1

You cannot assign directly from double to struct, instead you have to write the specific field field_name to assign to:

[StructureI(i).field_name, ReqTab(i), jt(i), B(i)] = Checkall(E);

If all of these variables (i.e. also ReqTab, jt, B) are structures, then off course you need to specify the field in each one of them, using the . notation.

However, as mentioned in the comments, all iterations of your loop are just the same (no usage of i within it), so why do you need this loop? just to make 5 copies?

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.