Hello,
I am new to programming, and trying to write a script to align multiple 4-column tables based on the first column. The first column are numbers in the order from small to large(you may think it as date). The numbers may be slightly different from table to table, and some tables may have more rows than the others. In the script I wrote below, it covers 4 tables(A,B,C,D), and generate the aligned table A. I can repeat the codes to generated aligned table B, C, D as well. However, my problem is that the number of input tables may vary from 4 to 20, and I don't want to revise my script every time. I have not figured out how to write such a script. Any suggestions are appreciated.
The script is the following:
function z=align4(A, B, C, D, reslst) % align matrices A, B, C and D
if nargin<5, reslst=[]; end %default: all resid.
if isempty(reslst), rlst=[min([A(:,1);B(:,1);C(:,1);D(:,1)]):max([A(:,1);B(:,1);C(:,1);D(:,1)])]'; % Generate a complete residue list.
else rlst=reslst(:);endnres=length(rlst);z=NaN*ones(nres,4);z(:,1)=rlst;for ii=1:nres, indA=find(A(:,1)==rlst(ii)); if ~isempty(indA), z(ii,2:end)=A(indA,2:end); end endreturn
Best Answer