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에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by