フィルターのクリア

How to plot for different parameter values of a, p1 and p2

4 ビュー (過去 30 日間)
vetri veeran
vetri veeran 2015 年 10 月 20 日
コメント済み: Image Analyst 2015 年 10 月 21 日
Hi all, I want to plot using different parameter values of a, p1 and p2 in the same plot in the following code. Like a = 1,2,3 , p1= 1,2,3 and p2= 1,2,3.
My code:
a = 1;
p1=1;
p2=1;
r1 = 1/2.*log2(1+(p1/(a+ p2)));
r2 = 1/2.*log2(1+(p2/(a)));
plot([0 r1],[r2 r2]);
hold on;
plot([r1 r2],[r2 r1]);
plot([r2 r2],[r1 0]);
Thanks
  2 件のコメント
TastyPastry
TastyPastry 2015 年 10 月 20 日
Can you be more specific as to what you're trying to plot on each axis? Currently your code plots 3 lines on the same plot. Are you trying to shorten your code?
vetri veeran
vetri veeran 2015 年 10 月 21 日
編集済み: vetri veeran 2015 年 10 月 21 日
I want to plot r1 and r2 on x and y axis respectively. Also, I need to compare the difference of r1 and r2 plot by using different values of a, p1 and p2.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2015 年 10 月 21 日
Try this:
% Define variables.
a = [1,2,3];
p1 = [1,2,3];
p2 = [1,2,3];
for index = 1 : length(p1)
subplot(2, 2, index);
r1 = 1/2. * log2(1+(p1(index) / (a(index)+ p2(index))));
r2 = 1/2 .* log2(1+(p2(index) / (a(index))));
fprintf('For index = %d, a=%d, p1 = %d, p2 = %d, r1 = %f, r2 = %f\n', ...
index, a(index), p1(index), p2(index), r1, r2);
plot([0 r1],[r2 r2], 'b*-', 'LineWidth', 3, 'MarkerSize', 15);
hold on;
plot([r1 r2],[r2 r1], 'b*-', 'LineWidth', 3, 'MarkerSize', 15);
plot([r2 r2],[r1 0], 'b*-', 'LineWidth', 3, 'MarkerSize', 15);
grid on;
caption = sprintf('a=%d, p1 = %d, p2 = %d', a(index), p1(index), p2(index));
title(caption, 'FontSize', 20);
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);
end
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
  2 件のコメント
vetri veeran
vetri veeran 2015 年 10 月 21 日
編集済み: vetri veeran 2015 年 10 月 21 日
Thank you for reply. Could you please tell me, How do I plot a=1,2,3 p1=1,2,3 and p2=1,2,3 in only one plot(X and Y) so that I can easily compare all the parameters of a, p1 ,p2.
Image Analyst
Image Analyst 2015 年 10 月 21 日
Delete the "subplot" line at the beginning of the for loop.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by