Since I'm new to programming I'm unable to figure out myself on how to rewrite this code to reduce it's runtime. I have written this program as my first homework but did not succeed 🙁 But I would like to complete it now and the program i wroke has a lot of "for" loops which is taking a lot of time to run the program. The program is about projecting two sets U and V in a bipartite graph and I have written the program separately both of them. (Where set U= actors and V= movies). Could you help me with a better choice/alternative for this code which reduces the runtime of the program?
% Projections of actors (set X)
adj_Xw = zeros(1049,1049);for i=1:1049 % columns
for a=1:1049 % rows
if (i>a) adj_Xw(a,i) = adj_Xw(i,a); elseif (i==a) adj_Xw(a,i) = 0; else for b=1:nm if (A(i,b)==1 && A(a,b)==1) adj_Xw(a,i) = adj_Xw(a,i) + 1; end end end endendadj_X = adj_Xw; for i=1:1100401 % Plain version of projection(X)
if adj_X(i)>0 adj_X(i)=1; endendX = graph(adj_X);Xw = graph(adj_Xw); save ('variables');%Projection of movies (set Y)
adj_Yw = zeros(345,345);for i=1:345 % columns for a=1:345 % rows if (i>a) adj_Yw(a,i) = adj_Yw(i,a); elseif (i==a) adj_Yw(a,i) = 0; else for b=1:na if (G(i+1049,b)==1 & G(a+1049,b)==1) adj_Yw(a,i) = adj_Yw(a,i) + 1; end end; end; end;end;adj_Y = adj_Yw; for i=1:119025 % Plain version of projection(Y)
if adj_Y(i)>0 adj_Y(i)=1; endend;Y = graph(adj_Y);Yw = graph(adj_Yw);
Best Answer