How would I generate a plot like this when data is in excel file?

조회 수: 1 (최근 30일)
Bryan Tassin
Bryan Tassin 2021년 8월 28일
댓글: Walter Roberson 2021년 8월 28일

답변 (1개)

Walter Roberson
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
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:
  1. Read the data from Excel
  2. Processing data that is in memory
  3. 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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by