how to solve this
3 次查看(过去 30 天)
显示 更早的评论
p=[101.3 106.6 109.4 114.7 116.9 118.2 123.7];
v=[1.69 3.67 4.37 5.45 5.84 6.05 6.90];
% 4 ways for interpolation
lin=interp1(v,p,5,'linear')
m=interp1(v,p,5,'makima')
sp=interp1(v,p,5,'spline')
n=interp1(v,p,5,'nearest')
% Display a graph of speed versus pressure, the graph will include the given measurements
as well as the results obtained using 4 methods interpolation.
Mark with a red asterisk the points where the speed is 5 [m/s.]
* Labels must be added to the axes, legend, grid lines and title.
0 个评论
采纳的回答
Image Analyst
2023-1-19
You almost got it. Maybe you just needed to read the manual some more and understand what is x and what is y.
p=[101.3 106.6 109.4 114.7 116.9 118.2 123.7];
v=[1.69 3.67 4.37 5.45 5.84 6.05 6.90];
plot(p, v, 'b.-', 'LineWidth', 2, 'MarkerSize', 20);
grid on;
xlabel('Pressure');
ylabel('Velocity');
% 4 ways for interpolation
xq = linspace(min(p), max(p), 500);
lin=interp1(p, v, xq,'linear') ;
m=interp1(p, v, xq,'makima');
sp=interp1(p, v, xq,'spline') ;
n=interp1(p, v, xq,'nearest');
% Find where speed is closest to 5
[value, index] = min(abs(lin - 5)) % Value is how far away from 5 the data point is.
x5 = xq(index)
y5 = lin(index)
hold on;
yline(5, 'Color', 'r') % Horizontal red line at 5.
xline(x5, 'Color', 'r') % Horizontal red line at 5.
% Plot a red asterisk at the point closest to y=5
plot(x5, y5, 'r*', 'MarkerSize', 30, 'LineWidth', 2)
Go ahead and add the rest, like legend, title, etc.
更多回答(1 个)
Walter Roberson
2023-1-19
When you call plot, you can use
plot(x1, y1, x2, y2, x3, y3, ...)
where x1 and x2 and x3 and so on might happen to all be the same.
For the part about red: see https://www.mathworks.com/help/matlab/creating_plots/create-line-plot-with-markers.html#bvcbmlx-1
4 个评论
Walter Roberson
2023-1-19
plot(v,p,lin,m,sp,n,'r*',5)
That code asks to use v as the first independent variable, and plot p as dependent on it. And then to take lin as the next independent variable and plot m as depedent on it.
Contrast to
plot(v, p, v, lin, v, ...)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
