我有3个列向量a,b和c,我必须在matlab中找到中值向量,即,例如,' a'是中位数矢量,然后prgram将输出作为' a'。 我怎么能这样做?
答案 0 :(得分:0)
使用
%initializes input
k=5; a = rand(k,1); b = rand(k,1); c = rand(k,1);
%calcualtes median value
medRes = median([a,b,c],2);
%calculate output string
res = repmat('c', k, 1);
res(medRes==a) = 'a';
res(medRes==b) = 'b';
结果:
[a b c] =
0.7060 0.8235 0.4387
0.0318 0.6948 0.3816
0.2769 0.3171 0.7655
0.0462 0.9502 0.7952
0.0971 0.0344 0.1869
res =
a
c
b
c
a