how to display {m,n} with its answer for example {1,2}=2?

1 回表示 (過去 30 日間)
suchismita
suchismita 2015 年 4 月 16 日
回答済み: Stephen23 2016 年 1 月 11 日
I have a set of 10 answer 2,3,5,6,3,7,3,2,4,5 i want to display them as
{1,2}=2;
{1,3}=3;
{1,4}=5;
{1,5}=6;
{2,3}=3;
{2,4}=7;
{2,5}=3;
{3,4}=2;
{3,5}=4;
{4,5}=5; please help me please please....
i will be so thankful

採用された回答

Stalin Samuel
Stalin Samuel 2015 年 4 月 16 日
out = [ 2,3,5,6,3,7,3,2,4,5]
count=0
for i= 1:4
for j=i+1:5
count = count+1;
result=out(count);
disp(sprintf('{%d,%d}=%d',i,j,result))
end
end
  1 件のコメント
suchismita
suchismita 2015 年 4 月 16 日
thank you so much....

サインインしてコメントする。

その他の回答 (1 件)

Stephen23
Stephen23 2016 年 1 月 11 日
There is no need for any loop, this is simpler and faster:
>> V = [2,3,5,6,3,7,3,2,4,5];
>> X = [nchoosek(1:5,2),V(:)];
>> fprintf('{%d,%d} = %d\n',X.')
{1,2} = 2
{1,3} = 3
{1,4} = 5
{1,5} = 6
{2,3} = 3
{2,4} = 7
{2,5} = 3
{3,4} = 2
{3,5} = 4
{4,5} = 5

カテゴリ

Help Center および File ExchangeNonlinear Optimization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by