|
Kuo-Hsien wrote:
...
> Please advice me some easier method to rearrange this question I'm trying to solve.
...
Easier than what, pray tell?
> % original data
> 1 22 333 44 2222
> 2 33 444 55 4444
> 3 44 555 66 6666
> 4 55 666 77 8888
> 5 66 777 88 2222
>
> % after matlab's arrangement, the new 5th column is the average of original 5th column
> 1 22 333 44 1111
> 1 22 333 44 1111
> 2 33 444 55 2222
> 2 33 444 55 2222
> 3 44 555 66 3333
The 5th column in the latter certainly isn't an average of the original;
rather it appears to be one-half the original value.
But, if that's what is wanted, something like the following is the
straightforward way...
>> a = [1 22 333 44 2222;
2 33 444 55 4444;
3 44 555 66 6666;
4 55 666 77 8888;
5 66 777 88 2222];
>> b=zeros(2*size(a,2),size(a,1));
>> nrows=size(a,1);
>> for i=1:nrows
i2=2*i-1;
b(i2,:)=a(i,:);
b(i2,5)=a(i,5)/2;
b(i2+1,:)=b(i2,:);
end
>> b
b =
1 22 333 44 1111
1 22 333 44 1111
2 33 444 55 2222
2 33 444 55 2222
3 44 555 66 3333
3 44 555 66 3333
4 55 666 77 4444
4 55 666 77 4444
5 66 777 88 1111
5 66 777 88 1111
--
|