MATLAB Answers

2D Graph Plot from excel data

4 views (last 30 days)
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!

Accepted Answer

Star Strider
Star Strider on 20 Jul 2021
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 Comments
Star Strider
Star Strider on 20 Jul 2021
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.
.

Sign in to comment.

More Answers (1)

Francesco Marchione
Francesco Marchione on 20 Jul 2021
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 Comment
Star Strider
Star Strider on 21 Jul 2021
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)
.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by