Using nested for loop to create a 3D matrix ?

조회 수: 1 (최근 30일)
Perrine Cristante
Perrine Cristante 2018년 6월 6일
답변: Perrine Cristante 2018년 6월 7일
Hello,
I have an ECG signal to parse to find values corresponding to a certain time window. The start and stop times of the window are respectively stored in QRSavgd and QRSavgf. X is my time scale.
B = [];
X = samples*1000/f;
A = horzcat(ECG(:,1:12),X.');
for i = 1:length(QRS)
for j = 1:length(ECG)
if A(j,13)>=QRSavgd(i) && A(j,13)<=QRSavgf(i)
B(:,:,j) = vertcat(B,A(j,:));
% plot(B);
end
end
end
I would like to store each B array found with the j loop in a 3D matrix so that I can differentiate each iteration of the j loop, to know which values I get when j=1, j=2...
Thanks
  댓글 수: 2
Stephen23
Stephen23 2018년 6월 6일
It does not make much sense to use both concatenation and indexing to collect your values:
B(:,:,j) = vertcat(B,A(j,:));
What are you hoping to achieve?
Perrine Cristante
Perrine Cristante 2018년 6월 6일
I would like to be able to overlap the QRSs on a plot, hence getting each individual QRS in a 3D plot x,y,z where x is the ECG derivation, y is the amplitude and z is the QRS index.

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

채택된 답변

Perrine Cristante
Perrine Cristante 2018년 6월 7일
I finally found how to do it using cell arrays instead of 3D matrix, so I'll put the solution for the ones with the same problem as me :
B = {};
X = samples*1000/f;
A = horzcat(ECG(:,1:12),X.');
for i = 1:length(QRS)
C = [];
for j = 1:length(ECG)
if A(j,13)>=QRSavgd(i) && A(j,13)<=QRSavgf(i)
C = vertcat(C,A(j,1:12));
end
end
B{i} = C;
end
This creates a 2D matrix named C and stocks it in the cell array named B.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by