Info

此问题已关闭。 请重新打开它进行编辑或回答。

Transform algorithm avoiding loops

1 次查看(过去 30 天)
MRC
MRC 2014-5-2
关闭: MATLAB Answer Bot 2021-8-20
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?

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by