MATLAB: I want to save all the value of variable a from all iterations into a single matrix f=[1 3 5 7 9 11; 2 4 6 8 10 12]; b=[1 2;3 4]; [m n]=size(f); [m c]=size(b); for k=1:n f1=f(:,k); for i=1:c b1=b(i,:); d=0; for j=1:m d=d+(f1-(b1)'); a(j)={sum(d)} Lt=sqrt(abs((a{j}))); end end end Best Answer % initial dataf=[1 3 5 7 9 11; 2 4 6 8 10 12];b=[1 2;3 4];% engineb=b';[nn,n]=size(f);[m,c]=size(b);aa=1:n;aa=aa(ones(c,1),:);aa=aa(:)';f=f(:,aa);bb=(1:c)';bb=bb(:,ones(1,n));bb=bb(:)';b=b(:,bb);% resultsa=cumsum(c*(f-b))'Lt=sqrt(abs(a)) Related SolutionsMATLAB: How to compare 3 matrix a=A(:,1:2)D=a(ismember(a,B(:,1:2),'rows') & ismember(a,C(:,1:2),'rows') ,:) MATLAB: Plot a defined function You can define ‘N’ as an anonymous function. Try this: N = @(T) 0.5*(sum(abs(eig(partialtranspose(T))))-1);Tv = linspace(0.1, 14, 10); % Define Rnage Of ‘T’for k = 1:numel(Tv) Nv(k) = N(Tv(k));endfigureplot(Tv, Nv)gridI used the loop because ‘partialtranspose’ is not vectorised. See the documentation on Anonymous Functions for more information on them. Related QuestionThree variable together in one loop in different sizeHow to create a block diagonal matrix without using cell arrayI have a problem with plotting two vectors, I want to vary ‘z’ by a certain amount and ‘x’ by another amount and plot versus each other, how can i make the matrix dimensions match
Best Answer