フィルターのクリア

Trouble with For Loop

2 ビュー (過去 30 日間)
Justin
Justin 2023 年 12 月 1 日
回答済み: Walter Roberson 2023 年 12 月 1 日
I am having trouble creating a for loop to repeat a set of code completed for 1 subject to the next 34 (in total 35 subjects). The data set has a row of ECG data per subject and it was extracted by dataN_1 = ecg_data (:,1). The data was later filtered and mean HR and RR intervals for the ECG were calculated for subject 1. How do I repeat everything but with different names e.g. mean_HR_subject1, mean_HR_subject2, etc. to calculate the mean and std for HR and HR variability for the 35 subjects?
Thank you!

採用された回答

Torsten
Torsten 2023 年 12 月 1 日
移動済み: Torsten 2023 年 12 月 1 日
for i = 1:35
dataN_(i) = ecg_data (:,i);
mean_HR_subject(i) = ...
...
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 12 月 1 日
If you need to compute different field names for a struct, or different property names for objects, you can use dynamic field names. It would look something like this,
for iteration = 1 : 35
HRfield = "HR_subject" + iteration;
mHRfield = "mean_" + HRfield;
data_in = TheStruct.(HRfield);
data_out = some calculation on data_in
TheStruct.(mHRfield) = data_out;
end
See also structfun
There are also useful techniques working with tables, such as rowfun and varfun and groupsummary -- you could potentially convert to table using struct2table

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by