フィルターのクリア

Generating matrix from another array

2 ビュー (過去 30 日間)
lilly lord
lilly lord 2020 年 9 月 10 日
コメント済み: lilly lord 2020 年 9 月 11 日
I am tring to generate a matrix S1,S2,S3 from an array E3 .
All three matrices should contain numbers from 0 to 25 but in the order it appears in E3, i.e in first S box 2,1,0,4,25,29 goes to S1 and for another 2 it will be added to S2, and for the next 2 it will check S1,S2 both and as both contain 2 so it will be added in S3. The code gives error so if anyone can help me in this regard.
E3=[2 1 0 4 25 19 2 2 3 3 4 5 6 7 8 7 19 .....];%800 numbers but value less than 26
S1=zeros(1,25); % for generating 5*5 mATRIX
S2=zeros(1,25);S3=[];
for i=1:lengtH(E3)
S1(i)=E3(i);
if ismember(S1,E3(i))
S2(I)=E3(i);
if ismember(S2,E3(i))
S3(i)=E3(i)
end
end
  1 件のコメント
BOB MATHEW SYJI
BOB MATHEW SYJI 2020 年 9 月 10 日
Hi, Can you please elaborate the question?

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

採用された回答

Stephen23
Stephen23 2020 年 9 月 10 日
編集済み: Stephen23 2020 年 9 月 10 日
>> E3 = [2,1,0,4,25,19,2,2,3,3,4,5,6,7,8,7,19];
>> X = diag(cumsum(bsxfun(@eq,E3,E3(:)),1));
>> C = arrayfun(@(n)E3(X==n),1:max(X),'uni',0);
>> C{1}
ans =
2 1 0 4 25 19 3 5 6 7 8
>> C{2}
ans =
2 3 4 7 19
>> C{3}
ans =
2
  1 件のコメント
lilly lord
lilly lord 2020 年 9 月 11 日
It works well. I got the required result. Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by