I have a matrix [0 1; 1 0]. I need to:
1) choose random row from this matrix
2) duplicate every non-zero element from this row with a some probability and add it to the matrix.
3) enlarge the size of the matrix (to keep it square)
4) repeate the procedure with the new matrix (with added row), say, 10 times.
The idea is to use this matrix to construct a graph (where zeros correspond to the absence of linkadge between two nodes and ones – to the presence of linkadge).
Now I stuck on the stage of enlarging the matrix: as every element of the randomly chosen row should be checked alone, matlab do not allow to add elements one-by-one in one cycle.
conmat = [0 1; 1 0] ;S=size(conmat,1);r=randi(S);sigma=0.3; a=rand;rndrow=conmat(r,:);rowadd=[];for j=1:size(conmat,1); if sigma>a rowadd(j)=[rowadd rndrow(j)] elseif sigma<a rowadd(j)= [0] endconmat=[conmat rowadd] %ERROR
coladd=transpose(conmat(3,:)) coladd=[coladd; 0]conmat=[conmat coladd]endError using horzcatDimensions of arrays being concatenated are not consistent.Error in network_181129 (line 15)conmat=[conmat rowadd]
I feel I need to use some different approach not syntaxis tricks but I'm not so experinced in coding and Matlab and already spent a lot of time on this problem. I will appreciate any help and ideas, thank you in advance!
Best Answer