Well, it's Friday after all...Here's half a dozen ways:
%// Method 0: beginning programmer
for i=0:1:2
c=A(i);
A(i)=B(i);
B(i)=c;
end
%// Method 1: MATLAB novice
[A,B] = deal([B(1:3) A(4:end)], [A(1:3) B(4:end)]);
%// Method 1.5: MATLAB novice+
[A(1:3), B(1:3)] = deal(B(1:3), A(1:3));
%// Method 1.8: ambitious MATLAB novice
function myFunction(A,B)
%//...
[A(1:3), B(1:3)] = swap(A(1:3), B(1:3));
%//...
function [a,b] = swap(b,a)
% look, no content needed!
%// Method 2: Freshman CS student looking to impress friends
A(1:3) = A(1:3)+B(1:3);
B(1:3) = A(1:3)-B(1:3); %// Look, no temporary!
A(1:3) = A(1:3)-B(1:3); %// Overflow? Pff, that won't ever happen.
%// Method 3: Overambitious CS master forced to use MATLAB
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
plhs[0]=prhs[1]; // (generated with AutoHotKey)
plhs[1]=prhs[0];
}
%// Method 4: You and way too many others
1. Go to http://www.stackoverflow.com
2. Ask "the internet" how to do it.
3. Wait until "the internet" has done your work for you.
5. Repeat from step 1 for every new question that pops up.
%// Method 5: GOD HIMSELF!
C = A(1:3); %// ...will simply use a temporary
A(1:3) = B(1:3);
B(1:3) = C;