Creating discretized grid without values, only text

Hi,
I'm trying to recreate a figure that looks similar to this one (reference: Introduction to computation and modeling for differential equations by Lennart Edsberg);
Any help would be greatly appreciated. I don't know how to create a plot without any values (only text on some of the discretizations), and when I create a grid it automatically grids both axis, I just want the x-axis discreticized.

 採用された回答

Star Strider
Star Strider 2018 年 10 月 14 日

2 投票

Try this:
x = 0:0.1:1;
y = 0.25;
figure
plot([x; x], [ones(1, numel(x))*0.5; zeros(1, numel(x))], 'k')
text(0, y, sprintf('\\itu\\rm(x_0,\\itt\\rm) = \\alpha(\\itt\\rm)'), 'Rotation',90, 'HorizontalAlignment','center', 'VerticalAlignment','top')
for k1 = 2:numel(x)-1
text(x(k1), y, sprintf('\\itu\\rm(x_%.0f,\\itt\\rm) = \\itu\\rm_%.0f(\\itt\\rm)',[10 10]*x(k1)), 'Rotation',90, 'HorizontalAlignment','center', 'VerticalAlignment','top')
end
text(1, y, sprintf('\\itu\\rm(1,\\itt\\rm) = \\beta(\\itt\\rm)'), 'Rotation',90, 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
ylabel('\itt')
Experiment to get the result you want.

2 件のコメント

Stephan
Stephan 2018 年 10 月 14 日
Nice +1
Star Strider
Star Strider 2018 年 10 月 14 日
Thank you!

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

その他の回答 (1 件)

Stephan
Stephan 2018 年 10 月 14 日

1 投票

Hi,
if you use R2018b then you can use the new introduced feature xline.
Here is a quick and dirty example:
x = [];
y = [];
plot(x,y)
xlim([0 1]);
lines = 0:0.1:1;
for k = 1:numel(lines)
xl(k) = xline(lines(k),'-',{'u(xi,t)=alpha(t)'});
xl(k).LabelVerticalAlignment = 'middle';
end
which results in:
Best regards
Stephan

2 件のコメント

Aram Eskandari
Aram Eskandari 2018 年 10 月 14 日
編集済み: Aram Eskandari 2018 年 10 月 14 日
Hey and thanks for your answer! I'm using Matlab R2018a, that doesn't seem to work for me. Is there another similar solution, or should I just go ahead and install the newest version?
Stephan
Stephan 2018 年 10 月 14 日
編集済み: Stephan 2018 年 10 月 14 日
You paid for R2018b, so why not use it...
Otherwise use the nice answer from Star Strider below.

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

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by