how to add variable to array

조회 수: 3 (최근 30일)
Dominik Smolinsky
Dominik Smolinsky 2021년 4월 30일
댓글: Benjamin Großmann 2021년 5월 3일
Hello guys.
I have breathVAL variable, which is showing the numbers - average of PPG and ECG signal. I need this numbers to average to one number. I know that i have to add this numbers to some array like breathVAL_total and than divide it with the length of this array. Can you help me please? Thanks.
function breathVAL = vaseFCE( PPG, ECG, fs)
%%UPRAVA EKG SIGNALU
[b, a] = fir1(2, 0.032, 'low'); %vytvorenie FIR filtra dolnej priepusti, 0.032 - medzni frekvence
y = filtfilt(b, a, ECG); %pre urceny EKG signal aplikujeme filter dolnej priepusti
[peaks, poloha] = findpeaks(y, 'MinPeakDistance', 320); %funkcia, ktora hlada vzdialenosti medzi peakmi v signale
ECG_sprac = length(poloha); %funkcia, ktory vyhodi pocet peakov v signale
%UPRAVA PPG SIGNALU
[b, a] = fir1(2, 0.032, 'low'); %vytvorenie filtra dolnej priepusti, filter 2 radu
y = filtfilt(b, a, PPG); %pre urceny PPG signal aplikujeme filter dolnej priepusti
[peaks, poloha] = findpeaks(y, 'MinPeakDistance', 320); %funkcia, ktora hlada vzdialenosti medzi peakmi v signale
PPG_sprac = length(poloha); %funkcia, ktory vyhodi pocet peakov v signale
breathVAL = (ECG_sprac + PPG_sprac) / 2; %priemer EKG a PPG signalu = vysledna hodnota breathVAL = odhad dychovej frekvencie
%breathVAL = 15*(mean(PPG) + mean(ECG)) + fs - fs;
end
  댓글 수: 4
Benjamin Großmann
Benjamin Großmann 2021년 4월 30일
If breathVAL is a 8000x1 array, then you can write
breathVAL_AVG = mean(breathVAL);
But looking at your code you wrote
breathVAL = (ECG_sprac + PPG_sprac) / 2;
ECG_sprac as well as PPG_sprac are the output of length() if you use matlabs function length, then the output is scalar and so is breathVAL. The result of mean() on a scalar value is the value itself.
Dominik Smolinsky
Dominik Smolinsky 2021년 4월 30일
Is there some method or function which can help me average all the scalars(breathVAL) to just one number?

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

답변 (1개)

Benjamin Großmann
Benjamin Großmann 2021년 4월 30일
Okay, maybe I understood the problem:
If you have an array of PPG and ECG values and a constant fs you could do something like:
fs = 100;
breathVAL_array = arrayfun(@(p,e) vaseFCE(p, e, fs), PPG_array, ECG_array);
breathVAL_mean = mean(breathVAL_array);
Arrayfun is calling your function vaseFCE for every element in PPG_array and ECG_array, calculating the scalar breathVAL and collecting them in breathVAL_array. After that you can call mean to get the average.
  댓글 수: 2
Dominik Smolinsky
Dominik Smolinsky 2021년 4월 30일
@Benjamin Großmann can i ask you where should i put this part of code? you have my code upper
Benjamin Großmann
Benjamin Großmann 2021년 5월 3일
It depends on how you call the function "vaseFCE" at the moment. Most often one can replace the call to a function directly with an arrayfun method.

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

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by