3 5 1
5 2 2
2 5 2
5 3 1
5 1 3
7 0 2
6 1 2
6 0 3
1 1 7
1 4 4
2 1 6
5 4 0
take 3+5=8--which is not equal to 9
so loop again rotate
take 3+2=5--not equal to 9
same in this manner 5+1=6 not valid 5+5=10 no same as this start from next entry and do process,take allentry as row wise if answer valid than loop stop and do for next element process

댓글 수: 11

David Barry
David Barry 2016년 12월 17일
I've read that a couple of times now and still have no idea what you are asking. Can you explain it better?
take element of matrix and sum with next element and check total =10 if not than take next element and again check sum
matrix(1,1)=3
3+5=8
3+1=4
3+5=8
3+2=8
3+2=5
3+2=5
3+2=5
3+2=5......3+7=10 loop stop
print-3 is valid
now matrix(1,2)=5
5+1=6
5+5=10...loop stop
5 is valid
matrix(1,3)=1
1+5=6
1+2=3
1+2=3
1+2=3...check with all other elements..except its own
Pratik Anandpara
Pratik Anandpara 2016년 12월 17일
@david Barry now got?
David Barry
David Barry 2016년 12월 17일
No still don't get it. Please upload a mat file containing your matrices.
Pratik Anandpara
Pratik Anandpara 2016년 12월 17일
편집: Pratik Anandpara 2016년 12월 17일
mat file is more complicated i take example matrix :
1 2 3
4 5 6
7 8 9
goal is total=10
now take 1+2=3
1+3=4...1
1+4=5
1+5=6
1+6=7
1+7=8
1+8=9
1+9=10
stop this process now
print...1 is valid after 8 process
now take 2+3=5
2+4=6
2+5=7
2+6=8
2+7=9
2+8=10
print...2 is valid 6 process
3+4=7
3+5=8
3+6=9
3+7=10....3 is valid after 4 process
4+5=9
4+6=10....4 is valid after 2 process
now
5+6=11
5+7=12.......upto 5+4=9
5 is not valid(not take own sum)
6+7=13.6+8=14...6+9=15...6+1=7...6+2=8...6+3=9...6+4=10
6 is valid after 7 process
like this take row wise sequence...random matrix take but process same
Pratik Anandpara
Pratik Anandpara 2016년 12월 17일
@david barry...still?....i will mail you if you stil not get
Image Analyst
Image Analyst 2016년 12월 17일
He might have given up because it's not well explained. So do you want to add every element to every other element, or even all possible other elements, until you find all the combinations that equal some desired integer value?
I have two more questions. (2) How large could this matrix be? and (3) have you tried a intuitive and simple brute force "for" loop?
Pratik Anandpara
Pratik Anandpara 2016년 12월 17일
use any loop ..matrix is mostly n*3 ..i tried force also but not set there
Image Analyst
Image Analyst 2016년 12월 17일
Let's see your brute force for loop attempt.
David Barry
David Barry 2016년 12월 17일
Yes I have given up. Poor explanation, no code and no data. I'm out.
Jan
Jan 2016년 12월 17일
I do not understand the explanations also. What do you want to achieve?

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

 채택된 답변

KSSV
KSSV 2016년 12월 18일

0 개 추천

Let A be your matrix.
B=A(:);
N = length(B);
iwant=zeros(N,2);
for i=1:N
count=0;
C=setdiff(B,B(i));
for j = 1:N-1
count=count+1;
if B(i)+C(j)==10
iwant(i,:)=[B(i) count];
break
end
end
end

댓글 수: 1

KSSV
KSSV 2016년 12월 18일
count is not required ...You can directly take j in place of count.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

태그

질문:

2016년 12월 17일

댓글:

2016년 12월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by