Filter löschen
Filter löschen

i have S 300x800 data set matrix , i need code for replacing coloumns

1 Ansicht (letzte 30 Tage)
i have S 300x800 data set matrix , i need code for replacing column 120 with 50,and 120 with 121,and 240 with 100 and 240 with 241 ,and 360 with 150 and 360 with 361,.. what is the easy way of doing it with large data set 50 matrix of 300x800 each ?
  2 Kommentare
Walter Roberson
Walter Roberson am 31 Dez. 2017
I notice that you have listed two replacement columns for each column. Are you looking to replace one column each time?
ihab
ihab am 31 Dez. 2017
no, i am switching between columns, switch 120 with 50 ,240 with 100, 360 with 150, 200 with 480, 250 with 600

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 31 Dez. 2017
I cannot claim that this is completely robust since I’ve experimented only with this code. I appears to do the same operation in one line, without the loops:
M = bsxfun(@times, ones(5,7), (1:7)) % Create Matrix
M(:,[2 5 7]) = M(:, [7 2 5]) % Switch Col#7 With Col#2, Col#2 With Col#5, Col#5 With Col#7
M =
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
M =
1 7 3 4 2 6 5
1 7 3 4 2 6 5
1 7 3 4 2 6 5
1 7 3 4 2 6 5
1 7 3 4 2 6 5
Experiment with it to see if it does what you want with your matrix.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 31 Dez. 2017
to_replace = 120:120:800;
for K = 1 : length(to_replace)
temp = OriginalMatrix;
temp(:,to_replace(K)) = temp(:,K*50);
NewMatrix{2*K-1} = temp;
temp = OriginalMatrix;
temp(:,to_replace(K)) = temp(:,to_replace(K)+1);
NewMatrix{2*K} = temp;
end

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by