# Creating a struct with means and standard deviations

1 ビュー (過去 30 日間)
BA 2022 年 9 月 16 日
コメント済み: BA 2022 年 9 月 16 日
I'd like to create a script that loops through multiple subjects and creates a new structure with doubles in it.
First Column of Master Table: I want the SubjectID but I only want it once, I don't want it repeating like it is in the dataset I've attached.
Second Column of Master Table: I want it to lead to a struct with the means of each of the six events. So in the new struct, I want the first column of the first row to be for event 1_a, second column first row event 2_a, etc.
Third Column of Master Table: I want it to lead to a struct with the standard deviation of each of the six events.
Here's an example of what I want it to look like:
The examples of mean and standard deviation doubles are only for one subject. I'd like to loop this for every subject in the data table to create a master struct.

サインインしてコメントする。

### 採用された回答

Chris 2022 年 9 月 16 日

It looks like you want an array of structs. Use strings or uint64 for the IDs
S = struct('id',uint64(123456),'mean',rand(3),'stdev',rand(1,3))
S = struct with fields:
id: 123456 mean: [3×3 double] stdev: [0.7411 0.1904 0.5026]
for idx = 2:4
S(idx).mean = rand(3);
S(idx).stdev = rand(1,3);
S(idx).id = uint64(randi(1e9));
end
S
S = 1×4 struct array with fields:
id mean stdev
% Retrieve data
x = S(3).stdev
x = 1×3
0.6080 0.0728 0.3028
y = [S(1:2).id]
y = 1×2
123456 614065544
##### 5 件のコメント表示非表示 4 件の古いコメント
BA 2022 年 9 月 16 日
Thank you! That works. Appreciate you for helping me out!

サインインしてコメントする。

### カテゴリ

Find more on Tables in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by