フィルターのクリア

How to sort data (multiple rows into one)

2 ビュー (過去 30 日間)
Nadine
Nadine 2021 年 3 月 15 日
コメント済み: Nadine 2021 年 3 月 16 日
I need to sort data from multiple rows in one row. We used multiple trials (= target_number) in an experiment and the software stored the target_type, number_picture, duration, cue_condition, current_cue_picture, etc. for each trial. I've colored below the data that belongs together to one trail:
I'm interested in the identification_button and identification_RT for each trial. So I guess the data must be sorted like:
Is there a way to sort it with MATLAB automatically?

採用された回答

Seth Furman
Seth Furman 2021 年 3 月 15 日
This sounds like a good use for unstack.
For example, suppose we have the following table, consisting of 3 consecutive trials and the names "a", "b", "c" and "d".
t =
12×2 table
Name Value
____ _____
"a" 82
"b" 91
"c" 13
"d" 92
"a" 64
"b" 10
"c" 28
"d" 55
"a" 96
"b" 97
"c" 16
"d" 98
We can create a Trial variable for grouping as follows
trial = floor( (0:height(t)-1) / length(unique(t.Name)))' + 1;
>> t.Trial = trial
t =
12×3 table
Name Value Trial
____ _____ _____
"a" 82 1
"b" 91 1
"c" 13 1
"d" 92 1
"a" 64 2
"b" 10 2
"c" 28 2
"d" 55 2
"a" 96 3
"b" 97 3
"c" 16 3
"d" 98 3
and then unstack the Value variable using Name as our indicator variable and grouping the values by trial number
>> unstack(t,'Value','Name','GroupingVariables','Trial')
ans =
3×5 table
Trial a b c d
_____ __ __ __ __
1 82 91 13 92
2 64 10 28 55
3 96 97 16 98
  1 件のコメント
Nadine
Nadine 2021 年 3 月 16 日
Perfect, thank you!

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

その他の回答 (1 件)

Nadine
Nadine 2021 年 3 月 15 日
Already answered it myself. =)
Extracted the values (right column, column 7) for each variable Name (column 6) and put all together in one table:
If there's an easier way -- just let me know!

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by