Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Transform algorithm avoiding loops

1 vue (au cours des 30 derniers jours)
MRC
MRC le 2 Mai 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
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?

Réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by