surf() plot adding axis

13 次查看(过去 30 天)
Moritz P.
Moritz P. 2015-6-22
评论: Moritz P. 2015-6-23
Hi everyone, I have been trying to add axis to a surf plot i have. I've tried various suggestions but can't get it to work. I have 3 matrices:
final -> 3460x300 double
spec -> 1x300 double (x-axis)
timedate -> 1x3460 double (y-axis)
The timedate matrix values are converted time and dates with date2num.
How would pot this with surf and get the spec range on the x-axis and the timedate range on the y-axis. I did surf(final) were the plot looks correct but without the right axis points as in spec and timedate. When i do surf(spec,timedate,final) the plot looks wrong but the axis are correct.
How could i solve this?
Any kind of help would be highly appreciated.
  3 个评论
Mike Garrity
Mike Garrity 2015-6-22
In this case, you actually should just be this:
surf(spec,timedate,final,'EdgeColor','none')
It does look like things are nonlinear on the timedate axis. What do you get if you do this?
plot(timedate)
does it look like a straight line,or does the slope change in the middle, or is it non-monotone?
Moritz P.
Moritz P. 2015-6-23
Hi Mike, plotting time, i get the following:

请先登录,再进行评论。

回答(2 个)

Star Strider
Star Strider 2015-6-22
I’m not certain what you’ve tried, but see if this gives you the result you want:
[SP,TD] = meshgrid(spec, timedate);
surf(SP, TD, final')
grid on
xlabel('spec')
ylabel('timedate')
zlabel('final')
Note the transpose (') in the surf call for your ‘final’ matrix. That’s required because of the way the ‘SP’ and ‘TD’ matrices are created.
  2 个评论
Moritz P.
Moritz P. 2015-6-22
Unfotunately, the matrix dimensions didn't agree.
I did forget to mention that I am missing data for a few time ranges, do you know how would ignore the missing parts and only plot the time for data which is present?
Star Strider
Star Strider 2015-6-22
I don’t have your data and you didn’t mention missing values before. That may be the reason the matrix dimensions didn’t agree.
You can either use griddedInterpolant to fill in the missing values, or create a (3460x300) matrix of NaN values, then assign the corresponding elements of your ‘final’ matrix to it. The NaN values will not plot.
The scatter3 plot is another option.

请先登录,再进行评论。


Kelly Kearney
Kelly Kearney 2015-6-22
It appears as though your samples are unevenly spaced in time. So when you plot vs time, certain parts appear squished and stretched compared to the version where you ignore time and assume constant spacing along both axes.
  2 个评论
Moritz P.
Moritz P. 2015-6-22
Yes, sorry I didn't mention that in the question. I am missing a few time ranges between the data. How would I ignore the missing parts and only plot the time for data which is present?
Kelly Kearney
Kelly Kearney 2015-6-22
You can fill in the missing portions of the dataset with NaNs. For example:
% Some fake data, with missing time slices
y = 1:300;
t = datenum(2015,1,1) + (0:365);
t(t >= datenum(2015,3,1) & t < datenum(2015,6,1)) = [];
ny = length(y);
nt = length(t);
z = peaks(max(ny,nt));
z = z(1:ny,1:nt);
% The full time vector
t2 = datenum(2015,1,1) + (0:365);
% Add NaNs where needed
[tf,loc] = ismember(t, t2);
znew = nan(ny, length(t2));
znew(:,loc) = z;
surf(t2,y,znew);
shading flat;
Note that this only works if all your t values are in t2. If not, you may have to use a more complicated method.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by