How would I generate a plot like this when data is in excel file?
1 view (last 30 days)
Show older comments
![](/matlabcentral/answers/uploaded_files/723359/81340640-A05A-4CA9-B67E-C1ED5059E3ED.jpeg)
Answers (1)
Walter Roberson
on 28 Aug 2021
In the case where you happen to have the Symbolic Toolbox available:
x = linspace(0,2*pi,50);
y = cos(tan(x.^2)+pi/2);
ax = gca;
plot(ax, x, y)
xtick_locations = (0:8)/4 * sym(pi);
xticks(ax, double(xtick_locations))
tickstrings = "$" + arrayfun(@latex, xtick_locations, 'uniform', 0) + "$";
xticklabels(ax, tickstrings);
ax.XAxis.TickLabelInterpreter = 'latex';
xlim([0, 2*pi])
If you do not have the Symbolic Toolbox, you can compute the tickstrings latex entries, but you need extra steps to account for the cases that should not show up as rational fraction times pi
1 Comment
Walter Roberson
on 28 Aug 2021
MATLAB does not care where you get the data, so you should be thinking of dividing your work into three sections:
- Read the data from Excel
- Processing data that is in memory
- Plotting the results that are in memory
Do not think about it as having to process data that is in an excel file: think about it as getting excel data into memory and then a phase of processing data where the processing phase does not have to care how the data reached it.
To read data from Excel these days, use readmatrix() for uniform data, or readtable() for data of mixed datatype. xlsread() is not recommended these days.
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!