Matlab小技巧
%剔除数组中,超过限制的元素 s = [1,2,3] s(s>2)=5 s(s<2)=-5 >>>s=[-5 2 5]
%将两个数字首尾相连,合并成一个数字,1 2 3 -> 123 a1 = [11 2 3]'; a2 = [4 5 6]'; % Convert both the numbers to strings b1 = num2str(a1); b2 = num2str(a2); % Concatenate the two strings element wise c1 = strcat(b1, b2); % Convert the result back to a numeric matrix result = str2num(c1)
%求两个点之间的Euclidean distance dist([2,2;1,1],[0,0]'); %注意将后面所求的点,转置