2014-03-03 85 views
0

這裏我試圖繪製變量rho的誤差(矩陣之間的標準差)。所有其他變量應保持不變。 我真正想做的是將rho作爲一個單獨的矢量存儲,並在每個循環中計算錯誤時存儲錯誤值。在循環中計算的繪圖值

任何想法?

%Variables: 
%MatrixGen.m: p,q - matrix size, rho- percentage complete, r - rank 
%NuclearNorm.m : Zincomplete 

clear 

p=10; q=10; 
r=2; 

for rho=0.1:0.3:0.9; 

    [Ztrue, Zincomplete] = MatrixGen(p,q,r,rho) 

    tic 
    [Zreconstructed] = NuclearNorm(Zincomplete) 
    toc 

    Error= norm(Ztrue-Zreconstructed, 'fro') 

    hold on 
    plot (rho, Error) 

end 

回答

1

'這是你的意思嗎?

%Variables: 
%MatrixGen.m: p,q - matrix size, rho- percentage complete, r - rank 
%NuclearNorm.m : Zincomplete 

clear 
p=10; q=10; 
r=2; 

rho = 0.1:0.3:0.9 
errors = zeros(size(rho)) 

for i=1:length(rho); 

    [Ztrue, Zincomplete] = MatrixGen(p,q,r,rho(i)) 

    tic 
    [Zreconstructed] = NuclearNorm(Zincomplete) 
    toc 

    errors(i) = norm(Ztrue-Zreconstructed, 'fro') 
end 

plot(rho, errors) 

end