Hello, I am trying to do the following operations in matlab but I have a problem with how to properly write my code using vectorization. This is just an example, m, n and the values of the vectors and matrices are just to illustrate my problem. In reality m and n can go up to 1000.
n=5; m=8;a=4*ones(m,1); a(2)=2;a(n)=3;b=2*ones(n,2);b(1,1)=5;b(3,1)=1;ind=3*ones(n,2); ind(1,2)=0;ind(3,2)=0; b(1,2)=0;b(3,2)=0;non=zeros(1,n);c=zeros(1,n);for i=1:n non(i)=nnz(ind(i,:)); c(i)=prod(a(ind(i,1:non(i)))'.^b(i,1:non(i)),2);end
I tried the following but it does not give correct results.
i=1:n;c=prod(a(ind(i,1:non(i))).^b(i,1:non(i)),2);
Thank you in advance
Best Answer