我正在使用Octave进行学校项目,以计算和绘制速度/加速度图。
我一直在尝试创建一个子图函数,这样就不必为每个子图都加硬
subplot(3, 1, 1);
plot(time, accn);
grid;
title('Acceleration vs Time')
xlabel('Time, (s)')
ylabel('Acceleration, (m/s^2)')
subplot(3, 1, 2);
plot(time, velocity);
grid;
title('Velocity vs Time');
xlabel('Time, (s)');
ylabel('Velocity, (m/s)');
是否可以创建与此类似的函数
subplot = subplotFunction(row, column, xaxis, yaxis, header, xaxisLabel,
yaxisLabel)
subplot(3, row, column);
plot(xaxis, yaxis);
grid;
title('header')
xlabel('xaxisLabel')
ylabel('yaxisLabel')
endfunction
然后这样称呼它?
subplot = subplotFunction(1, 1, time, accn, 'Acceleration vs Time', 'Time, (s)', 'Acceleration, (m/s^2)')
我对使用函数还很陌生,所以我很抱歉:(
答案 0 :(得分:1)
1;
function subplotFunction(row, column, idx, xaxis, yaxis, header, xaxisLabel, yaxisLabel)
subplot (row, column, idx);
plot (xaxis, yaxis);
grid on;
title (header)
xlabel (xaxisLabel)
ylabel (yaxisLabel)
endfunction
subplotFunction (3, 1, 1, 1:10, 11:20, "foo", "bar", "baz")
subplotFunction (3, 1, 2, 1:10, 11:20, "huhu", "haha", "hoho")
x = linspace (0, 10, 100);
subplotFunction (3, 1, 3, x, sin(x), "world", "boo", "doo")
print ("out.png")
给予