I have the following code, i am entering value manually
i want to do it using for loop how can i do that and save data in 1x1000 in mat file
prfDS = [200 500 800 1000 800 900];
n_pulsesDS = [120 400 1200 1500 600 350];
prfDS(1:120) = 200
prfDS(121:520) = 500
prfDS(521:1720) = 800
prfDS(1721:3220) = 1000
prfDS(3220:3820) = 800
prfDS(3820:4720) = 900
scatter(1:length(prfDS),prfDS)

댓글 수: 1

Stephen23
Stephen23 2022년 2월 21일
편집: Stephen23 2022년 2월 21일
The last interval shown in your example indexing is inconsistent with the provided data:
cumsum([120,400,1200,1500,600,350])
ans = 1×6
120 520 1720 3220 3820 4170

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

 채택된 답변

Stephen23
Stephen23 2022년 2월 21일
편집: Stephen23 2022년 2월 21일

0 개 추천

The simple and efficient MATLAB approach would be to use REPELEM, for example:
val = [200,500,800,1000,800,900];
num = [120,400,1200,1500,600,350];
out = repelem(val,num)
out = 1×4170
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200
numel(out)
ans = 4170

댓글 수: 4

Med Future
Med Future 2022년 2월 21일
@Stephen How can i convert it into 1x1000 form and save in .mat file
Stephen23
Stephen23 2022년 2월 21일
편집: Stephen23 2022년 2월 21일
"How can i convert it into 1x1000 form..."
You would have to generate a 1x1000 vector from your 1x4170 vector, e.g. perform some interpolation, subsampling, take the first or last 1000 elements, or use one of many other approaches. Which approach you pick depends on you and your needs, which you have not told us.
"...and save in .mat file"
Med Future
Med Future 2022년 2월 21일
@Stephen how i can generate random values above
Stephen23
Stephen23 2022년 2월 21일
편집: Stephen23 2022년 2월 21일

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2022년 2월 21일

편집:

2022년 2월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by