I have two structures in a for loop with i = 1:n
A(i).a
B(i).b
For each loop i, the field a of structure A contains a double array with r(i) rows and 1 column, and the field b of structure B contains a double array with r(i) rows and m columns. In other words, the number of rows of the double array in the field of each structure changes with i and it is the same for both structures and equal to r(i). Also, the number of columns in field a of structure A is fixed and equal to 1, and the number of columns in field b of structure B is fixed and equal to m.
For each loop i, I want to find out the column index for each row of the double array contained in field b of structure B of the element which has a value equal to the value of the element on the same row of the double array contained in field a of structure A. For each loop i, the result should be a double array with 1 column and a number of rows equal to the number of rows of the double array in each field. I want to store the result in a structure R(i).r.
I tried the following, but it only works when the number of rows of the double arrays is equal to 1. When the number of rows of the double arrays is >1, I get all kind of wrong numbers!
R(i).r = find(B(i).b(:,:) == A(i).a(:));
Thank you very much!
5 Comments
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705329
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705329
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705497
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705497
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705499
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705499
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705668
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705668
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705671
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/462188-finding-corresponding-values-in-double-arrays-in-structure-fields#comment_705671
Sign in to comment.