MATLAB Answers

0

Could anyone help me how to store the result together in single matrix.

Asked by jaah navi on 19 Sep 2019
Latest activity Commented on by jaah navi on 19 Sep 2019
code:
B=[1 2;
1 3;
2 5;
2 4;
3 5;
4 6;
4 5]
for i=1:7
bbb= 1:6;
bb= B(i,1:2)
bbb= setdiff(bbb,bb)
result= [bb,bbb]
end
the above code executes and gives the result ,but i need to store all the result together in one matrix.Could anyone please help me on it.

  3 Comments

B=[1 2;
1 3;
2 5;
2 4;
3 5;
4 6;
4 5]
for i=1:7
bbb= 1:6;
res.bb= B(i,1:2)
res.bbb= setdiff(bbb,bb)
res.result= [bb,bbb]
end
you can save as structure into workspace. Are you looking something similar?
@Ankit, note that your code overwrites the result every iteration.
@rik yes I didnt notice that thanks for pointing out!

Sign in to comment.

1 Answer

Answer by Adam
on 19 Sep 2019
 Accepted Answer

Making minimal changes to your code:
B=[1 2;
1 3;
2 5;
2 4;
3 5;
4 6;
4 5]
for i=1:7
bbb= 1:6;
bb= B(i,1:2)
bbb= setdiff(bbb,bb)
BB(i,:) = [bb,bbb]
end
though it could be made neater.
It would be good if you didn't keep opening questions to ask the same thing many times. Sooner or later people will just stop answering at all.

  2 Comments

I'm already at the point I only open some of the questions. Judging by whose comments/answers I see I'm not the only one.
if
BB =[ 1 3 2 4 5 6;
3 4 1 2 5 6;
1 5 2 3 4 6;
2 3 1 4 5 6;
4 5 1 2 3 6;
1 6 2 3 4 5;
4 6 1 2 3 5;
5 6 1 2 3 4]
now i want to group the number into sets
with respect to all the rows the first two numbers needs to be grouped into one set{1 3},then for rest of the numbers it needs to check with respect to all the rows first two numbers if it remains to be same then the next two numbers needs to be grouped or else the next three numbers needs to be grouped {2 4 5} and the last number should be as {6}.
for second row {3 4} {1 2 5} {6}
for third row {1 5} {2 3} {4 6}
for fourth row{2 3}{1 4 5} {6}
and so on.
could you please help me on this.

Sign in to comment.