Unique and vectors last variable (simulink)
8 ビュー (過去 30 日間)
古いコメントを表示
Jani Vainionpaa
2022 年 2 月 2 日
コメント済み: Benjamin Thompson
2022 年 2 月 4 日
I got up to 32 vectors with six variables. I would like to remove whole vectors with multiple last variables(6) and keep the rest.
C01 = uint32([1;0;0;0;0;BANK1]);
C02 = uint32([0;1;0;0;0;BANK2]);
C03 = uint32([0;0;1;0;0;BANK3]);
C04 = uint32([0;0;0;1;0;BANK4]);
C05 = uint32([0;0;0;0;1;BANK5]);
Les's say bank 1=5, 2=10, 3=10, 4=20 and 5=0. So the idea is that bank 2 or 3 should be removed, since the value(6) has already been used earlier. But I need to have other vectors safe as whole.
Saved as output:
1 0 0 0 0 5
0 1 0 0 0 10
0 0 0 1 0 20
0 0 0 0 1 0
Removed:
0 0 1 0 0 10
with unique I only know how to check the final variable(6) but everything else of the vector will be lost during process.
Thanks!
1 件のコメント
Benjamin Thompson
2022 年 2 月 2 日
How is this related to Simulink? Can you post an example model showing what you are trying to do?
採用された回答
Benjamin Thompson
2022 年 2 月 2 日
Maybe use this approach in your MATLAB function block or add a separate MATLAB function block to modify the CONNECTION_OPTIONS matrix? Here I call unique twice. Use the 'stable' argument the first time so that column index order in the ic return vector is preserved. Then call unique on that column index vector to remove the repeated values.
>> C = [zeros(5,1) eye(5)]
C =
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
>> CXX = [C; BANK]
CXX =
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
0 5 10 10 20 0
>> [c, ia, ic] = unique(CXX(end,:), 'stable')
c =
0 5 10 20
ia =
1
2
3
5
ic =
1
2
3
3
4
1
>> CXX(:,unique(ia))
ans =
0 1 0 0
0 0 1 0
0 0 0 0
0 0 0 1
0 0 0 0
0 5 10 20
2 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Sources についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
