フィルターのクリア

Adding rows and column to existing inter dependency matrix

2 ビュー (過去 30 日間)
Santhosh Chandrasekar
Santhosh Chandrasekar 2018 年 2 月 19 日
Hi, how to change the below mentioned 'A' matrix to 'AA' matrix by adding a row and column of 'CR' with the exact values for 'CR' as mention below. For 'CR' all the values in the row from CR to E221 will have 0 and in the column, CR will be zero and E1 to E221 will be 1. I want that string 'CR' also need to be added to the existing headings of E1 to E221 in the row and column wise. I have also attached my code for A matrix and the new AA matrix should be an extension of this code.
nm= cellstr(reshape((string({'E','R','E','S','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR',}) + ([101,1,106,1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] + (0:4)'))',[],1))
N = zeros(44);
N(2:end,1)= 1
N(3:end,2)= 1
N(4,3)= 1
N(5:end,4)= 1
N(25,5)= 1;N(26,6)= 1;N(27,7)= 1;N(28,8)= 1;N(29,9)= 1;N(30,10)= 1;N(31,11)= 1;N(32,12)= 1;N(33,13)= 1;N(34,14)= 1;N(35,15)= 1;N(36,16)= 1;N(37,17)= 1;N(38,18)= 1;N(39,19)= 1;N(40,20)= 1;N(41,21)= 1;N(42,22)= 1;N(43,23)= 1;N(44,24)= 1;
N1=N;
T= repmat({N1},1,5)
A= [{nan},nm';nm,num2cell(blkdiag(T{:}))]
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 2 月 19 日
Do you have R2013b or later? If so then have you considered using a table() object with RowNames ?
Santhosh Chandrasekar
Santhosh Chandrasekar 2018 年 2 月 19 日
I have R2017. Can you please tell me how to do it using a table?

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2018 年 2 月 19 日
編集済み: Andrei Bobrov 2018 年 2 月 20 日
s = string({'CR';'E';'R';'S';'SR'});
[x,y] = ndgrid(1:20,[2,5]);
str = s([2;3;2;4;y(:)]) + ([101;1;106;1;x(:)] + (0:4));
str = cellstr([s(1),str(:)']);
d = {tril(ones(44,4),-1),diag(ones(20,1),-24)};
d{1}(4:end,3) = 0;
d{2} = d{2}(:,1:end-4);
dd = repmat({[d{:}]},1,5);
dd = [zeros(1,221);[ones(220,1),blkdiag(dd{:})]];
out = [{nan},str;str(:), num2cell(dd) ];
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2018 年 2 月 20 日
編集済み: Andrei Bobrov 2018 年 2 月 20 日
I am fixed my answer.
Here we can not use table - duplicate 'variable name'.
Santhosh Chandrasekar
Santhosh Chandrasekar 2018 年 2 月 20 日
I have updated my script thank you, sir!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by