MATLAB Answers

## how to draw vertical lines on the plot?

Asked by Olga

### Olga (view profile)

on 14 Mar 2012
Accepted Answer by Walter Roberson

### Walter Roberson (view profile)

Hello, I'm doing HRV spectral analysis and I want draw vertical lines around freq bands on my plot. It'd be great if each area could be in different colour. If anyone could give me any tip, shall be very grateful ;)

I need to add this to this plot:

```%Calculate PSD
[PSD,F] = pwelch(odstepRR,128,64,[],fs); %uses a hamming window
```
```      VLF = [0.0033 0.04];
LF = [0.04 0.15];
HF = [0.15 0.4];```
```      % find the indexes corresponding to the VLF, LF, and HF bands
iVLF= (F>=VLF(1)) & (F<=VLF(2));
iLF = (F>=LF(1)) & (F<=LF(2));
iHF = (F>=HF(1)) & (F<=HF(2));```
```      % calculate areas, within the freq bands (ms^2)
aVLF=trapz(F(iVLF),PSD(iVLF));
set(handles.vlf, 'string', num2str(aVLF));
aLF=trapz(F(iLF),PSD(iLF));
set(handles.lf, 'string', num2str(LF));
aHF=trapz(F(iHF),PSD(iHF));
set(handles.hf, 'string', num2str(aHF));
aTotal=aVLF+aLF+aHF;
set(handles.tp, 'string', num2str(aTotal));```
```      %calculate LF/HF ratio
lfhf =aLF/aHF;```
```axes(handles.axes5);
set(handles.text45, 'visible', 'on')
set(handles.axes5, 'visible', 'on')
```
```%plot area under PSD curve
area(F(:),PSD(:),'FaceColor',[.6 .6 .6]);
```
```grid on;
```

## Products

No products are associated with this question.

## 1 Answer

### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 14 Mar 2012
Accepted answer
```line([X X], [LowY HighY])
```

for example,

```line([5 5], [0.1 17])
```

to draw a line from (5,0.1) to (5,17)

#### 0 Comments

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

New to MATLAB?