matlab 表示一组向量S={a1,a1,a1...(T1个a1),a2,a2,...(T2个a2),.an,an,...(Tn个an}

问题描述:

matlab 表示一组向量S={a1,a1,a1...(T1个a1),a2,a2,...(T2个a2),.an,an,...(Tn个an}
其中,a1,a2,a3,...an,还有T1,T2,T3,...Tn都是已知的整数,不用for循环如何实现构造S向量?

T = [2 3 5 7];
a = [1 3 7 9];
fun = @(a,T)a.*ones(1,T);
S = cell2mat(arrayfun(fun,a,T),'un',false)我刚刚跑了下你的程序>> T = [2 3 5 7];a = [1 3 7 9];fun = @(a,T)a.*ones(1,T);S = cell2mat(arrayfun(fun,a,T),'un',false)??? Error using ==> arrayfunNon-scalar in Uniform output, at index 1, output 1.Set 'UniformOutput' to false.% 对不起,最后一句错了T = [2 3 5 7];a = [1 3 7 9];fun = @(a,T)a.*ones(1,T);S = cell2mat(arrayfun(fun,a,T,'un',false))