用直线连接数据点 (MatLab)

Joining data points with straight lines (MatLab)

我有一个非常简单的 MatLab 代码,可以很好地绘制 6 个数据点。 dt 列表中的 x 坐标;第 7 行 TempTable table 的 y 坐标。一切正常,我只需要 用直线 .[=15= 连接点]

% Plotting T_new(7) vs. dt
dt=[0.001,0.005,0.01,0.05,0.1,0.25]    % The time steps
y=[300,320,330,340,345,350]

for i=1:1:6     % Looping through all temperature profiles
    hold all;       
    plot( dt(i), y(i), 'b*-', 'LineWidth', 1);
    title(['Temperatures at nodal point 7']);
    xlabel( 'dt [s]' );
    ylabel( 'T [\circC]' );
    set( gca, 'LineWidth', 1 );
    axis( [ dt(2)-0.1, dt(6)+0.1, 300, 350 ] );
    pause( 0.1 );     % Animation step time
end

b*- 中的破折号 - 不应该添加这些连接线,或者什么?这里缺少什么,因为他们没有?

你的循环是你的问题。每次迭代只绘制一个点,Matlab 不可能知道连接哪些点。所以如果你想使用循环,你必须用另一个 plot-statement 手动连接这些点。

没有循环的解决方案可以是:

hold all;       
plot( dt, TempTable(7,:), 'b*-', 'LineWidth', 1);
title(['Temperatures at nodal point 7']);
xlabel( 'dt [s]' );
ylabel( 'T [\circC]' );
set( gca, 'LineWidth', 1 );
axis( [ dt(2)-0.1, dt(6)+0.1, 300, 350 ] );
pause( 0.1 );     % Animation step time