필터 지우기
필터 지우기

Plot specific rows with an defined offset

조회 수: 8 (최근 30일)
James Alix
James Alix 2021년 9월 27일
댓글: Star Strider 2021년 9월 28일
I have some spectral data, with points along individual spectra are in columns (there are 901 columns) and each row is a different sample (e.g. might have 12 samples): this is matrix "a".
I then have another set of data ("b") which has some scores which represent the amount of offset each sample must have on the plot I'm trying to produce. So "b" is a single column of data with 12 rows. The rows in "a" and "b" match in terms of samples i.e. row 1 = sample 1 in both.
I wish to plot the spectra in matrix "a", with each spectrum having a y offset that is given by the corresponding score in matrix "b": the rows in each match so row 1 is sample one in both "a" and "b". So, if the score the first row in "b" was 1.5, I would want the first spectrum in "a" offset by 1.5... and so on for all samples.
Next, I wish to generate another plot in which the samples (rows) in "a" are only plotted when the scores in "b" are either >0.5 or <-0.5 ..... For example:
Row 1 in "b" has a score of 1.5 so the row 1 spectrum in "a" is plotted with an offset of 1.5.
Row 2 in "b" has a score of 0.3, so row 2 spectrum in "a" is not plotted.
Row 3 in "b" has an entry of 1.2, so row 3 is plotted with an offset of 1.2.
Any help would be greatly appreciated!

채택된 답변

Star Strider
Star Strider 2021년 9월 27일
One approach —
f = 0:49;
Spectra = rand(10, 50);
Scores = randn(10,1);
Offset = Scores;
Offset((Offset>-0.5) & (Offset<0.5)) = NaN
Offset = 10×1
-0.7186 NaN -0.8784 -0.6020 1.1341 NaN -0.9134 2.7814 -1.0031 2.1508
figure
plot(f, Spectra+Offset)
Experiment to get different results.
.
  댓글 수: 2
James Alix
James Alix 2021년 9월 28일
Brilliant! Thanks++
Star Strider
Star Strider 2021년 9월 28일
Thank you!
As always. my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by