subplot(1,3,2)
plot(a1,x1, 'black', a1, y1, 'r', a1,z1, 'b',LineWidth=5);
title('Consumption level, T=10')
xticks([0 1 2 3 4 5 6 7 8 9])
xticklabels({'0' '1' '2' '\color{red}S^*' '4' '5' '6' '7' '8' '9'})
ylim([60,90])
How can I add vertical line at the level s* from 0 to the black line?
Thank you,

 採用された回答

Voss
Voss 2023 年 11 月 1 日

1 投票

x = 3;
y = interp1(a1,x1,x);
line([x,x],[0,y])

4 件のコメント

Raushan
Raushan 2023 年 11 月 1 日
Error using griddedInterpolant
The sample points must be finite.
Error in interp1 (line 170)
F = griddedInterpolant(X,V(:,1),method);
Error in plot10 (line 29)
p = interp1(a1,x1,l);
It shows me this erroe
Voss
Voss 2023 年 11 月 1 日
編集済み: Voss 2023 年 11 月 1 日
Sounds like you have some non-finite elements (NaN or Inf). Try this:
x = 3;
idx = isfinite(a1) & isfinite(x1);
y = interp1(a1(idx),x1(idx),x);
line([x,x],[0,y])
Raushan
Raushan 2023 年 11 月 1 日
thank you, it doesn't work, i don't have infinite one
Sam Chak
Sam Chak 2023 年 11 月 1 日
All you have to do is to provide the data for a1 and x1. We will figure out what the issue is.
If both a1 and x1 are in the Workspace, then save them to a MAT-file, using this syntax
save('RaushanData', 'a1', 'x1')
Once completed, attach the MAT-file (RaushanData.mat) using the paperclip icon .
By the way, both approaches by @Voss and @Star Strider work when the all elements in the data are finite.
a1 = 0:9; % hypothetical data
a1e = [min(a1) max(a1)] % extrema of a1
a1e = 1×2
0 9
x1 = linspace(8, 78, numel(a1)); % hypothetical data
x1e = [min(x1) max(x1)] % extrema of x1
x1e = 1×2
8 78
xq = 3; % from S* mark (query point)
yq = interp1(a1e, x1e, xq); % interpolate
% Plot data (black line)
plot(a1, x1, 'black', LineWidth=5);
xticks([0 1 2 3 4 5 6 7 8 9])
xticklabels({'0' '1' '2' '\color{red}S^*' '4' '5' '6' '7' '8' '9'})
hold on
% Plot vertical line (red)
plt = line([xq, xq], [0, yq]); % primitive line drawing
plt.LineWidth = 5;
hold off
title('Consumption level, T=10')

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

タグ

質問済み:

2023 年 11 月 1 日

編集済み:

2023 年 11 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by