How to plot multiple answers on the same graph
2 ビュー (過去 30 日間)
古いコメントを表示
I have produced the following code. However, I have multiple values for rnl = 0, 0.0015, 0.0020, 0.0025. How could I update the code so that it will run and plot the four different values for rnl on the same graph?
% Set the parameters for the test problem.
N = 64; % The image is N-by-N.
theta = 4:4:180; % Projection angles.
rnl = 0; % Relative noise level.
kmax = 800; % Number of iterations.
% Generate the test problem.
[A,b_ex,x_ex] = paralleltomo(N,theta);
% Add noise; we scale the noise vector e such that
% || e ||_2 / || b_ex ||_2 = relative noise level (rnl)
rng(0); % Initialize random number generator.
e = randn(size(b_ex)); % Gaussian white noise.
e = rnl*norm(b_ex)*e/norm(e); % Scale the noise vector.
b = b_ex + e; % Add the noise to the pure data.
% Run Kaczmarz's method and compute the error history and its minimum.
X = kaczmarz(A,b,1:kmax);
E = zeros(kmax,1);
for k=1:kmax
E(k) = norm(x_ex-X(:,k));
end
E = E/norm(x_ex);
[minE,K] = min(E);
figure(1), clf
plot(1:kmax,E,'-g',K,minE,'*g','linewidth',1.5,'markersize',6)
legend('Relative error','Minimum')
xlabel('Iterations')
ylabel('Relative error')
3 件のコメント
採用された回答
Star Strider
2021 年 6 月 25 日
‘The code is using AIR Tools toolbox.’
I have no idea what that is, and I can’t find it in the File Exchange.
I have no idea what the variables are that use ‘rnl’ in their calculations, or their sizes, so this could be as easy as vector multiplication or could require a for loop.
Try something like this (loop approach):
for k = 1:numel(rnl)
e{k} = rnl(k)*norm(b_ex)*e/norm(e); % Scale the noise vector.
end
It will then be necessary to use loops to do any other calculations with the cell array ‘e’. Address elements of ‘e’ as ‘e{k}’ in any subsequent calculations using it.
This, and subsequent calculations, could easily be vectorised, if the sizes of the variables were known and they permitted vectorisation. Lacking that information, loops are the only reliable approach.
.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Discrete Data Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!