是的吧,循环容易些:clear all;clc;a=2;R=rand(4,6);k=[2 3 4];g=[3 5 6];for ii=1:length(k) s(ii)=R(k(ii),g(ii));endS=a*sum(s)