how to compare 2 double array
Show older comments
Suppose i have 4 double array a(i,j) of size 256*8 elements and y(i1,j1),z(i2,j2) and b(i3,j3)having size of 1*8,1*8,1*50 elements.
I want to compare all the rows of a(i,j) with y(i1,j1),z(i2,j2) and b(i3,j3). The condition is
if (a(i,j)==y(i1,j1) or a(i,j)==z(i2,j2)) and b(i)==0
a(i,j)=y(i1,j1);
elseif b(i)==1
a(i,j)=z(i2,j2);
can anybody write the code perfectly.
2 Comments
Jan
on 15 Nov 2016
It is unlikely that forum users will write code for you. We all have out own projects to work on. But if you show, what you have tried so far, suggestions for improvements are likely.
In addition to what Jan and KSSV said, the test does not appear to make much sense. As written, it is
- if b(i) is 1, (whatever i refers to) then the values of a, y and z don't matter, just assign something from z to something from a.
- if b(i) is 0, then if something from a matches something from y or z then assign something for y to something from a
- if b(i) is 0, but the something from a matches neither y nor z, then nothing happens
That's not very symmetrical so probably not what is intended.
Note all the something in the above. That's because the notation used is very confusing and I've no idea what all the indices are supposed to be. Are these indices totally independent, resulting in a comparison of all the elements of a (256*8 elements) with all combinations of the elements of y , z, and b (8*8*50), for a total of (256*8)*(8*8*50) comparisons or should only column 1 of a be compared to column 1 of y and z (but to all columns of b?)? Perhaps, only rows of a should be compared to columns of b (since they both use the same index i) but it is stated that a has 256 rows while b only has 50 columns...
Accepted Answer
More Answers (1)
KSSV
on 15 Nov 2016
0 votes
Why someone has to write code for you?
doc find, ismember, ismemebrtol.
As the numbers are flottant, find, == may not work. In that case ismemebrtol should work. Or get the difference of the numbers you are comparing and see whether the the difference is less then the tolerance limit, which you have to provide.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!