
How can I code on a plot several lines and a name for each line? (coding a simple EEG)
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Star Strider
2015년 11월 13일
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
Andrew Michalak
2022년 4월 21일
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
2022년 4월 21일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!