How would I generate a plot like this when data is in excel file?
1 次查看(过去 30 天)
显示 更早的评论
回答(1 个)
Walter Roberson
2021-8-28
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 个评论
Walter Roberson
2021-8-28
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!