필터 지우기
필터 지우기

how to compare 2 double array

조회 수: 21 (최근 30일)
aditya kumar sahu
aditya kumar sahu 2016년 11월 15일
편집: Image Analyst 2016년 11월 15일
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
Jan
Jan 2016년 11월 15일
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.
Guillaume
Guillaume 2016년 11월 15일
편집: Guillaume 2016년 11월 15일
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...

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2016년 11월 15일
편집: Image Analyst 2016년 11월 15일
I see nothing inherently wrong with your code other than using "and" and "or" for && and . And not having an "end" on your if/else block of course. Fix those problems and I think it should work with numbers that are integers or powers of 2. Of course your indexes i, j, i1, j1, i2, j2, i3, and j3 all need to be defined of course, perhaps in a for loop or whatever.
If you have fractions (non-integers and not inverse powers of 2), then see the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

추가 답변 (1개)

KSSV
KSSV 2016년 11월 15일
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.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by