フィルターのクリア

How to find unique value in serial order??

1 回表示 (過去 30 日間)
Triveni
Triveni 2016 年 1 月 26 日
コメント済み: the cyclist 2016 年 1 月 26 日
I have a matrix
p = [90 90 -45 0 0 45 45 0 -45];
i want unique values in serial order from right side
q = [90 -45 0 45 0 -45];
Means from right side first value is -45, second is 0, third is 45...etc
I want repeated unique number according to serial from RHS.
Means sort repeated values.

採用された回答

the cyclist
the cyclist 2016 年 1 月 26 日
編集済み: the cyclist 2016 年 1 月 26 日
Does this do what you want?
p = [90 90 -45 0 0 45 45 0 -45];
idx = [true diff(p)~=0];
q = p(idx);
If not, can you give another example or two that illustrates the rule?
  2 件のコメント
Triveni
Triveni 2016 年 1 月 26 日
The Cyclist Sir,
I have inserted an image. Here every p(9) values are interchange/swap by q(length(q-1)); and store & store temporary copy to c(:,:,1). then p(9) or c(1,9,1) interchange/swap by q(length(q-2)); and save temporary copy to c(:,:,2). then p(9) or c(1,9,2) interchange/swap by q(length(q-3)); and save temporary copy to c(:,:,3). and so on. can you make a program for me. I'll be very thankful to you.
the cyclist
the cyclist 2016 年 1 月 26 日
Is this a homework problem? If so, can you show some work that you tried yourself?
You can see my comment on Walter's solution, to see the way to get q.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 1 月 26 日
q = p;
q(1+find(q(1:end-1)==q(2:end))) = [];
  2 件のコメント
Triveni
Triveni 2016 年 1 月 26 日
Thanks walter Sir, Actually i seen late...please solve my another query....can i find positions of matrix q according to p from RHS. means q= [90 -45 0 45 0 -45] & layer location according to p is [2 3 5 7 8 9]
the cyclist
the cyclist 2016 年 1 月 26 日
p = [90 90 -45 0 0 45 45 0 -45];
pLR = fliplr(p);
idxLR = [true diff(pLR)~=0];
locationsLR = find(fliplr(idxLR))

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by