surf() plot adding axis

28 views (last 30 days)
Moritz P.
Moritz P. on 22 Jun 2015
Commented: Moritz P. on 23 Jun 2015
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 Comments
Mike Garrity
Mike Garrity on 22 Jun 2015
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. on 23 Jun 2015
Hi Mike, plotting time, i get the following:

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 22 Jun 2015
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 Comments
Moritz P.
Moritz P. on 22 Jun 2015
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 on 22 Jun 2015
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.

Sign in to comment.


Kelly Kearney
Kelly Kearney on 22 Jun 2015
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 Comments
Moritz P.
Moritz P. on 22 Jun 2015
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 on 22 Jun 2015
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.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!