How can I generalise this?

1 Ansicht (letzte 30 Tage)
Muhammad Nazmi Bin Mohd Ropi
Beantwortet: Sarthak am 7 Mär. 2023
My manual copies of rows code works. but im trying to generalise it into a working algorithm. How do i generalise this?
n = 12
m = n(n-1)/2;
n = 64^2;
S = zeros(m,n);
SFull = zeros(2*m,n);
SFull(1:11,:) = S(1:11,:);
SFull(12,:) = S(1,:);
SFull(13:22,:) = S(12:21,:);
SFull(23,:) = S(2,:);
SFull(24,:) = S(12,:);
SFull(25:33,:) = S(22:30,:);
SFull(34,:) = S(3,:);
SFull(35,:) = S(13,:);
SFull(36,:) = S(22,:);
SFull(37:44,:) = S(31:38,:);
SFull(45,:) = S(4,:);
SFull(46,:) = S(14,:);
SFull(47,:) = S(23,:);
SFull(48,:) = S(31,:);
SFull(49:55,:) = S(39:45,:);
SFull(56,:) = S(5,:);
SFull(57,:) = S(15,:);
SFull(58,:) = S(24,:);
SFull(59,:) = S(32,:);
SFull(60,:) = S(39,:);
SFull(61:66,:) = S(46:51,:);
SFull(67,:) = S(6,:);
SFull(68,:) = S(16,:);
SFull(69,:) = S(25,:);
SFull(70,:) = S(33,:);
SFull(71,:) = S(40,:);
SFull(72,:) = S(46,:);
SFull(73:77,:) = S(52:56,:);
SFull(78,:) = S(7,:);
SFull(79,:) = S(17,:);
SFull(80,:) = S(26,:);
SFull(81,:) = S(34,:);
SFull(82,:) = S(41,:);
SFull(83,:) = S(47,:);
SFull(84,:) = S(52,:);
SFull(85:88,:) = S(57:60,:);
SFull(89,:) = S(8,:);
SFull(90,:) = S(18,:);
SFull(91,:) = S(27,:);
SFull(92,:) = S(35,:);
SFull(93,:) = S(42,:);
SFull(94,:) = S(48,:);
SFull(95,:) = S(53,:);
SFull(96,:) = S(57,:);
SFull(97:99,:) = S(61:63,:);
SFull(100,:) = S(9,:);
SFull(101,:) = S(19,:);
SFull(102,:) = S(28,:);
SFull(103,:) = S(36,:);
SFull(104,:) = S(43,:);
SFull(105,:) = S(49,:);
SFull(106,:) = S(54,:);
SFull(107,:) = S(58,:);
SFull(108,:) = S(61,:);
SFull(109:110,:) = S(64:65,:);
SFull(111,:) = S(10,:);
SFull(112,:) = S(20,:);
SFull(113,:) = S(29,:);
SFull(114,:) = S(37,:);
SFull(115,:) = S(44,:);
SFull(116,:) = S(50,:);
SFull(117,:) = S(55,:);
SFull(118,:) = S(59,:);
SFull(119,:) = S(62,:);
SFull(120,:) = S(64,:);
SFull(121,:) = S(66,:);
SFull(122,:) = S(11,:);
SFull(123,:) = S(21,:);
SFull(124,:) = S(30,:);
SFull(125,:) = S(38,:);
SFull(126,:) = S(45,:);
SFull(127,:) = S(51,:);
SFull(128,:) = S(56,:);
SFull(129,:) = S(60,:);
SFull(130,:) = S(63,:);
SFull(131,:) = S(65,:);
SFull(132,:) = S(66,:);
  3 Kommentare
Sulaymon Eshkabilov
Sulaymon Eshkabilov am 8 Feb. 2023
It is all "0"s, what is the purpose?
Muhammad Nazmi Bin Mohd Ropi
not zeros, i used fread not shown here.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sarthak
Sarthak am 7 Mär. 2023
Hi,
To generalize your code into a working algorithm, you can use a loop to iterate over each row of your input matrix, and then copy the row to the output matrix if it meets the desired criteria.
Inside the loop, to copy the matrix ‘A’ row into ‘B’ matrix, use the following line of code:
B = [B; A(i,:)];

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by