Transform algorithm avoiding loops
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
Hi, I have to transform the following algorithm in an algorithm without loops.
Consider a matrix A with the following characteristics:
A=[[1 2; 1 3; 1 4; 2 1; 2 6; 3 1; 3 2; 3 3; 3 4; 3 5] randi([0,1], 10,2)];
In particular, the characteristics of A which I can rely on are: the first column shows all increasing numbers from 1 to n=3, but we don't know how many times each number is repeated; for each number from 1 to n=3, some numbers between 1 and m=6 are associated in the second column, not necessarily in an increasing order.
I construct a vector Y of dimension (size(A,1))x1 in the following way:
n=max(A(:,1));
m=max(A(:,2));
gamma=2;
delta=-3;
Y=zeros(size(A,1),2);
for t=1:m
At=A(A(:,2)==t,:);
for l=1:size(At,1)
Yl= mvnrnd((gamma/delta*At(l,3:end))',eye(n-1)); %1x(n-1)
ismember(A(:,1:2),[At(l,1) t],'rows');
Y(index,:)=Yl
end
end
I want to rewrite the algorithm above without loops. Could you help me?
Antworten (0)
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!