Surfc error in plotting

I am trying to use surfc to plot 3 variables-time, height, temp. I have imported these variables in from an excel worksheet and have converted them to arrays. When using surfc, I receive an error stating my Z values must have more than one row or column. This is what I have done so far:
temp=table2array(table(:,1)
height=table2array(table(:,2)
time=table2array(table(:,3)
[x,y]=meshgrid(time,height)
z=temp
surfc=(x,y,z)
Any help would be appreciated.
As a side note, I tried to use contour but found an error since my values are not purely in an ascending or descending order. Thanks!

Answers (1)

Please do not use table as the name of a variable, especially when you are using table objects. Below I will use datatable()
temp = datatable{:,1};
height = datatable{:,2};
time = datatable{:,3};
heightvec = linspace(min(height), max(height));
timevec = linspace(min(time), max(time));
[x, y] = meshgrid(timevec, heightvec);
z = griddata(time, height, temp, x, y);
surf(x, y, z, 'edgecolor', 'none')

7 Comments

I will keep that in mind for future. The program worked, and was successful(so Thank you so much!!), however, I am wondering if it is possible, like when using the plot function, to incorporate a 'hold on' to graph multiple data sets on a surfc plot? I have about 26 flights I would like to incorporate on this graph.
You can use hold on there, but unless you set Alpha values, the later surfaces are going to hide the earlier surfaces unless they are at non-overlapping locations.
I had tried to use the 'hold on' function prior to commenting, and it did not work, but figured it out, thank you. After completing the graph, I do not think visually it looks like what I would prefer it to. Is it possible to have the time on the x-axis, height on the y-axis, and plot temperature based on these two variables?
That is what the current code should do. But could you check that your input has time as the third column and temperature as the first column? Normally those would be the other way around.
I am sorry, I am not really sure how to execute your request. Would you please tell me how I am to check this?
Your code extracts time from the third column of your data file. Please check your data file to verify that the time is stored in column 3. It is possible, but it would be unusual: time is usually before the data being me.
Attached is the result I get when I move the graph to depict only the x- and z-axis. The problem is temperature is on the y-axis, taking away the color scheme desired (which is showing how the temperature changes based on the height). When checking my data, I found that the time is in the second column, but when inputting the time variable into the command window, the results are those of time.

Sign in to comment.

Tags

Asked:

on 4 Jan 2018

Commented:

on 5 Jan 2018

Community Treasure Hunt

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

Start Hunting!