2D Graph Plot from excel data

22 次查看(过去 30 天)
Hello,
I would like to plot a load-displacement graph with two curves, from excel data.
The result I would like to obtain (in terms of graphics) is that attached.
Thank you!

采纳的回答

Star Strider
Star Strider 2021-7-20
I have absolutely no idea what you want to plot, and the data posted do not give anything similar to the plot image.
Other than that, if you want to load the Excel file and plot the data, womething like this will work.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/690238/Load-displacement.xlsx', 'VariableNamingRule','preserve')
T1 = 29×5 table
s (mm) F (N) Var3 s (mm)_1 F (N)_1 ______ _____ ____ ________ _______ 0 0 NaN 0 0 0.01 200 NaN 0.01 250 0.02 400 NaN 0.02 500 0.03 600 NaN 0.03 750 0.04 800 NaN 0.04 1000 0.05 1000 NaN 0.05 1250 0.06 1200 NaN 0.06 1500 0.07 1400 NaN 0.07 1750 0.08 1600 NaN 0.08 2000 0.09 1800 NaN 0.09 2250 0.1 2000 NaN 0.1 2500 0.11 2200 NaN 0.11 2750 0.12 2400 NaN 0.12 3000 0.13 2600 NaN 0.13 3250 0.14 2800 NaN 0.14 3500 0.15 3000 NaN 0.15 3750
figure
plot(T1.('s (mm)'), T1.('F (N)'))
grid
Experiment to get the result you want.
.
  4 个评论
Francesco Marchione
I attach the same result from the Excel graph. I have two different curves plotted together in the same graph.
Moreover, I would like to set a determined value for y and x axes (for examples 10000 N for y axis and 0.50 mm for x axis).
I would also like two decimals numbers displayed for x axis (that is s[mm]). For example, I would like to read 0.10 instead of 0.1 mm.
Finally, I would like a legend for the curves (ADH1 and ADH2) with the frame, as in the "Legend" attached image.
Thank you so much.
Star Strider
Star Strider 2021-7-20
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/690238/Load-displacement.xlsx', 'VariableNamingRule','preserve')
T1 = 29×5 table
s (mm) F (N) Var3 s (mm)_1 F (N)_1 ______ _____ ____ ________ _______ 0 0 NaN 0 0 0.01 200 NaN 0.01 250 0.02 400 NaN 0.02 500 0.03 600 NaN 0.03 750 0.04 800 NaN 0.04 1000 0.05 1000 NaN 0.05 1250 0.06 1200 NaN 0.06 1500 0.07 1400 NaN 0.07 1750 0.08 1600 NaN 0.08 2000 0.09 1800 NaN 0.09 2250 0.1 2000 NaN 0.1 2500 0.11 2200 NaN 0.11 2750 0.12 2400 NaN 0.12 3000 0.13 2600 NaN 0.13 3250 0.14 2800 NaN 0.14 3500 0.15 3000 NaN 0.15 3750
figure
plot(T1.('s (mm)'), T1.('F (N)'), T1.('s (mm)_1'), T1.('F (N)_1'))
grid
xlabel('F (N)')
ylabel('s (mm)')
legend('ACH_1','ACH_2', 'Location','best')
That is the best I can do with that file.
.

请先登录,再进行评论。

更多回答(1 个)

Francesco Marchione
I have modified the code in this way:
T1 = readtable('AA1.xlsx', 'VariableNamingRule','preserve')
figure
plot(T1.('s (mm)'), T1.('F (N)'), T1.('s (mm)_1'), T1.('F (N)_1'),'LineWidth',1)
grid
xlim([0 0.30])
ylim([0 10000])
ylabelname = sprintf('Load [N]','${D_{i}}$' );
ylabel(ylabelname, 'fontsize', 11, 'interpreter', 'latex')
set(gca,'xticklabel',num2str(get(gca,'xtick')','%.2f'))
L=legend('ADH1','ADH2', 'Location','best');
set(L,'Interpreter','latex')
set(gca,'TickLabelInterpreter','latex')
How can I set the xlabel name? If I write
xlabelname = sprintf('Displacement [mm]','${D_{i}}$' );
the label disappears.
I would also like to choose the colors for the two different curves (e.g., the first in red and the second dotted in blue).
I tried a lot but I did not succeed.
Thanks
  1 个评论
Star Strider
Star Strider 2021-7-21
I have no idea what you are trying to do.
There is no such thing as ‘xlabelname’ or ‘ylabelname’, only xlabel and ylabel.
Taking a wild guess
xlabel(sprintf('Load [N]','${D_{i}}$'), 'Interpreter','latex')
ylabel(sprintf('Load [N]','${D_{i}}$'), 'Interpreter','latex')
What is the reason for the sprintf calls? They do not appear to be doing anything that the character strings themselves could do.
The revised plot call would be —
plot(T1.('s (mm)'), T1.('F (N)'), '-r', T1.('s (mm)_1'), T1.('F (N)_1'),':b', 'LineWidth',1)
.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by