repacing a value by another

조회 수: 6 (최근 30일)
kash
kash 2012년 2월 9일
I have a matrix of 100x6 for ex let me take 6x6
[1 2 3 4 5 6
11 58 12 8 2 12
2 10 36 69 1 20
14 85 94 20 36 5
19 58 41 52 69 87
10 25 36 78 01 25]
now i want to replace the values as this,taking evry 2 elements in column wise as a pair,
for ex 1&11 must be replaced by a number 0.1
2 and 14 must be replaced by 0.2
19and 10 must be replaced by 0.3 (these for first column)
for 2nd column the values must be replaced is 2.0,2.1,2.2.....
please help
  댓글 수: 1
Jan
Jan 2012년 2월 9일
I do not understand the pattern. Do the new values depend on the old values, or just on the indices? Why is "19 and 10" replaced by 0.3?

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 2월 9일
A =rand(100,6);
[i1,j1] = ndgrid( 1:ceil(size(A,1)/2),1:size(A,2));
i1(:,2:end) = i1(:,2:end) - 1;
j1(:,1) = j1(:,1) - 1;
k=max(max(ceil(log10(i1))));
i1 = i1./10.^(k);
out = reshape(permute(repmat(i1+j1,[1,1,2]),[2 3 1]),size(A,2),[])';

추가 답변 (0개)

카테고리

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