Plotting a table as 3d mesh where x = columns, y = rows, z = cell value
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
1 vote
I am trying to plot EEG data as a 3d mesh or surface so I am then able to export it to a CAD program such as Fusion 360.
My data comes from an excel spreadsheet, and this is how it is set up / how I would like to plot it:
X = row number (time)[47100 rows]
Y = column number (channel)[64 columns]
Z = cell value (voltage)[positive and negative]
I am just importing the data by going to import data then import as table. I am new to matlab but I have been doing my best to learn it, so please let me know what I am doing wrong in my search or if there is a way to do this simply because I am coming up with nothing for using data that is in this configuration. If you know of a way I would be able to change it to better work, that would be fine. I just need the plot points and matlab is the only way to get plot them so I am able to export to CAD.
Accepted Answer
Star Strider
on 5 Mar 2017
0 votes
The scatter3 function might be most appropriate.
If you want a surface and your data are gridded (the easiest way to determin this is by plotting them with the stem3 function), then consider experimenting with the griddedInterpolant function. If they are not gridded, consider using the scatteredInterpolant function.
See the documentation for information on using the functions most effectively.
12 Comments
I have been looking at scatter3, however I have no idea what to enter or the x,y,z. This is the example I am looking at.
figure [X,Y,Z] = sphere(16); x = [0.5*X(:); 0.75*X(:); X(:)]; y = [0.5*Y(:); 0.75*Y(:); Y(:)]; z = [0.5*Z(:); 0.75*Z(:); Z(:)]; scatter3(x,y,z)
Where are these 3 values for x coming from [0.5*X(:); 0.75*X(:); X(:)] and how would I make it so my X = row number (1 through 47100) or Y = Column (A through BL)
I can't find any information explaining what those numbers are or how to use a data value rather then an equation are but my biggest problem is X = row number (rather then a cell within a row)
bob bob
on 6 Mar 2017
This is a sample of my data. That is all the columns but there is 47100 rows.
I just don't get how to reference The column and rows as x and y without defining each one?
Star Strider
on 6 Mar 2017
Save your data as a ‘.mat’ file and try again.
When I tried to open your file using xlsread, I got:
Error using xlsread (line 249)
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Office has detected a problem with this file. To help protect your computer this
file cannot be opened.
Help File: xlmain11.chm
Help Context ID: 0
Error in Elipses (line 61683)
d = xlsread('EEG1.xls');
bob bob
on 6 Mar 2017
I believe this is correct now.
Star Strider
on 6 Mar 2017
The table apparently lost some information, such as channel number and time.
See if this does what you want:
d = load('EEG.mat');
EEG_Table = d.EEG1;
M = table2array(EEG_Table);
t = 1:size(M,1); % Time Vector
figure(1)
ribbon(t, M, 0.2)
grid on
xlabel('Channel Nr')
ylabel('Time (ms)')
zlabel('mV')
view(45, 65)
axis tight
See the documentation on ribbon for details.
bob bob
on 6 Mar 2017
Channel and time were not labeled.
Is there a way to plot it as a surface rather then ribbon?
bob bob
on 6 Mar 2017
That is doing what I want though! I just want a surface rather then ribbon. I want to export this surface as an .stl do you know how I would incorporate that?
I have been trying to use this one
Star Strider
on 6 Mar 2017
When you mentioned plot3, I thought you wanted something like ribbon. If you want a surface plot use the surf function. A mesh plot might be easier to interpret.
The table in the ‘.mat’ file did not contain any channel or time information. The channel numbers will be displayed as the x-axis. If you have a time vector for the y axis, you can use it. If ‘M’ is your matrix surface, plot it as:
figure(1)
surf(channel, time, M)
grid on
You can also use the meshc function to display a contour plot below the plotted surface.
I am not familiar with ‘.stl’ files. I just looked at the description of the function. I have never done anything with stereolithography.
bob bob
on 6 Mar 2017
Ok, I really am stuck. I can't figure out in the world to map a mesh out of this. I tried looking into surf and meshc but I still don't understand how tell the program what my x, y, and z are. Do i need to first extrapolate the data out of the table then run surf?
Star Strider
on 6 Mar 2017
‘I can't figure out in the world to map a mesh out of this.’
Unless the data you posted earlier differs in some significant way from the data you extracted it from (since you mention having 47100 time samples in each channel), plotting a mesh surface is not difficult.
The Code —
d = load('EEG.mat');
EEG_Table = d.EEG1;
M = table2array(EEG_Table); % Extract Table Data To Double Array
t = 1:size(M,1); % Time Vector
c = 1:size(M,2); % Channel Vector
figure(1)
mesh(c, t, M)
grid on
xlabel('Channel Nr')
ylabel('Time (ms)')
zlabel('mV')
view(45, 65)
axis tight
The Plot —

I cannot help you with the ‘.stl’ file since I have no experience with them. If you are having problems with the File Exchange contribution function, it is best to contact the author.
bob bob
on 7 Mar 2017
OK thank you so much, the double array is where I start to get lost a little. I didn't understand where the z value is being pulled from. But that worked for me thank you again!!
Star Strider
on 7 Mar 2017
My pleasure!
More Answers (0)
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)