How do I use multiple markers for multiple lines in a single graph?

2 件のコメント

dpb
dpb 2022 年 10 月 23 日
What have you tried??? plot documentation has example, specifically named...
Mahfuzur Rahman
Mahfuzur Rahman 2022 年 10 月 23 日
I tried following:
x = [0 : 300]
f = [0.015, 0.028, 0.054, 0.067, 0.08]
for i=1:length(f)
y = f*x;
plot(x,y,'-d','LineWidth',1, 'MarkerSize',5)
end
But this code will give only diamond marker in all the lines. I need different markers for different lines as per figure.

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

 採用された回答

Image Analyst
Image Analyst 2022 年 10 月 23 日
Try this:
x = [0 : 300];
f = [0.015, 0.028, 0.054, 0.067, 0.080];
markerIndexes = 1 : 30 : length(x);
markerShapes = {'d', 'o', 's', '^', 'v'};
for k = 1 : length(f)
y = f(k) * x;
% Plot solid line in blue.
plot(x, y,'b-','LineWidth',1)
hold on
% Plot markers at subsampled points in red.
hp(k) = plot(x(markerIndexes), y(markerIndexes), 'linestyle', 'none', 'Color', 'r', 'Marker', markerShapes{k}, 'MarkerSize',5);
legendStrings{k} = sprintf('f = %.3f GHz', f(k));
end
grid on;
legend(hp, legendStrings, 'Location', 'northwest')
xlabel('x')
ylabel('y')

3 件のコメント

Mahfuzur Rahman
Mahfuzur Rahman 2022 年 10 月 23 日
Thanks. I tried this with another code and it runs perfectly. Do you have any source or link so that I can learn more about this process?
Image Analyst
Image Analyst 2022 年 10 月 23 日
Yes. Try this
Thanks for already Accepting my answer. 🙂
Mahfuzur Rahman
Mahfuzur Rahman 2022 年 10 月 25 日
Great. Thanks

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by