|
"Andreas " <snanreit@am.uni-erlangen.de> wrote in message <i9rnrv$o9j$1@fred.mathworks.com>...
> Hello everybody,
>
> can you please help me to vectorize the following code:
>
> R = zeros(oldnk,6);
> for i = 1:oldnk
> R(i,:)=find(A(i,:));
> end
>
> A is an adjacency matrix and I want to transfer the indices of the non-zeros elements in a row to a matrix R.
>
> Thank for you help.
Hi Andreas,
It is also possible to make indexing by logical variables. In that case R would be a matrix of logical values
R = A~=0;
Should the (double!) indeces be needed, the following command would be used after the upper one:
R = diag(1:size(A,1))*R;
Hope it helps.
Mira
|