필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
ihab
ihab 2017년 12월 31일
댓글: Star Strider 2017년 12월 31일
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
Walter Roberson
Walter Roberson 2017년 12월 31일
I notice that you have listed two replacement columns for each column. Are you looking to replace one column each time?
ihab
ihab 2017년 12월 31일
no, i am switching between columns, switch 120 with 50 ,240 with 100, 360 with 150, 200 with 480, 250 with 600

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2017년 12월 31일
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.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 12월 31일
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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by