
How can I code on a plot several lines and a name for each line? (coding a simple EEG)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi!
I'm trying to code a simple EEG. So my problem here is to plot several lines on an axe, and write as Y-axe not especially the scale, but the name of which channel is plotted.
any idea?
0 comentarios
Respuestas (1)
Star Strider
el 13 de Nov. de 2015
Here is one option:
t = linspace(0, 1, 500); % Time Vector
EEG = rand(10, 500)*0.005; % Simulate EEG (mV)
ofst = [1:size(EEG,1)]*0.005 + 0.001; % ‘Offset’ Vector
EEGp = bsxfun(@plus, EEG', ofst)'; % Add ‘Offset’ To Each Row
figure(1)
plot(t, EEGp) % Plot EEG
axis([xlim 0 0.055]) % Set Axis Limits
ChC = regexp(sprintf('Ch-%02d ', [1:size(EEG,1)]), ' ', 'split'); % Y-Tick Labels
yt = ofst+0.0025; % Y-Yick Positions
set(gca, 'YTick',yt, 'YTickLabel',ChC(1:end-1)) % Set Tick Labels
You will have to experiment with the code to get the result you want with your actual data:

4 comentarios
Andrew Michalak
el 21 de Abr. de 2022
Hi Star, thanks for this! I had a similar approach but one issue is that the Y axis ("amplitude") ends up being invalid in this case. plot_multichan runs into the same problem, and multichanplot seems to avoid the issue by disabling querying the Y axis? Any idea if any newer matlab versions offer a solution to the issue, where you can generate essentially the same visual output as your code but each channel has its own Y=0?
Star Strider
el 21 de Abr. de 2022
There are two that I am aware of (in addition to subplot that has been around since the earliest versions).
One is stackedplot (introduced in R2018b) and the other is tiledlayout (introduced in R2019b). They have different requirements and require different coding, however they will likely do what you want.
The stackedplot function may be closest to what you want to do.
Ver también
Categorías
Más información sobre EEG/MEG/ECoG en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!