I hope your day is going well. I have an issue I am unable to succinctly describe, so I will instead demonstrate it.
Let's say I have two structures:
A.a = zeros(10, 10, 10) + 1;
A.b = zeros(10, 10, 10) + 2;
A.c = zeros(5, 5) + 3;
B.a = zeros(10, 10, 10) + 1;
B.b = zeros(10, 10, 10) + 1;
B.c = zeros(5, 5) + 1;
As can be seen, A and B have the same size for each respective array in their structure. Ex. A.a is the same size as B.a. However, A.a and B.c are not the same size (A.a being 3d and B.c being 2d).
I would like to subtract each array with these two structures from each other. If I were doing only one array, it would look something like this:
C = bsxfun(@minus, A.a, B.a);
This returns a 3d array with all zeros since A.a and B.a are exactly equal.
I would like to do this for A.a - B.a, A.b - B.b, A.c - B.c, etc. In this example I have only 3 arrays in the strucutre for the sake of brevity and simplicity, but in my actual I have several arrays in each structure. I understand I could write a For Loop which iterates through each name in the structure, but I feel that using the Structfun and Bsxfun I could do this in significantly less code in a much less complicated way. However, I am unsure how to use Structfun such that I have two structures as inputs. Could you help me figure this out?
Any suggestions would be greatly appreciated. Thank you!