简体   繁体   中英

How to swap a number of the values between 2 columns in Matlab

I have a matrix with the size of 10x100. How can I swap the values between column 1 and column 10 in the first 40% of the rows?

You can use:

A = rand(10,100);

A(round(1:0.4*size(A,1)),[1,10]) = A(round(1:0.4*size(A,1)),[10,1]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM