How can i write any vector into short form?

2 ビュー (過去 30 日間)
Triveni
Triveni 2016 年 6 月 28 日
コメント済み: Triveni 2016 年 6 月 29 日
I have a vector
V = [0 0 0 -45 45 45 -45 90 90]
i want to view it as countable form i.e
[(0)3, -45, (45)2, -45, (90)2]
or
[(0)*3, -45, (45)*2, -45, (90)*2]
or any other counted form. May be by using symbolic tool. please help me.

採用された回答

Stephen23
Stephen23 2016 年 6 月 28 日
編集済み: Stephen23 2016 年 6 月 28 日
You could use Jan Simon's excellent FEX submission RunLength:
>> V = [0,0,0,-45,45,45,-45,90,90];
>> [X,N] = RunLength(V);
>> str = sprintf(', (%d)*%d',[X;N]);
>> str(3:end)
ans = (0)*3, (-45)*1, (45)*2, (-45)*1, (90)*2
The ones, because they are a special case, must be dealt with separately. One possibility is to simply replace those parts of the string:
>> regexprep(str(3:end),'\((-?\d+)\)\*1,','$1')
ans = (0)*3, -45 (45)*2, -45 (90)*2
  1 件のコメント
Triveni
Triveni 2016 年 6 月 29 日
Can i count + and - part together??
V = [0 0 0 -45 45 45 -45 45 -45 45 -45 90 90]
i want to write it as
[(0)*3, (-+45), (+-45)*3, (90)*2]

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by