How do I extract a vector from a single field in a structured variable?
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to create a vector variable from a field of an 8x1 structure.
To create the structure I used the dir function - I am trying to create a vector of subfolders name and set the code up so that it can take out the names if different folders were in the original folder.
I type:
folders_temp = dir('data_CLEANED');
folder_names = folders_temp(~ismember({folders_temp.name},{'.','..'})); %just doing this to get rid of dot and dot dot
participant_ID = [folder_names.name]
The participant names all crammed together in a single cell
Is there a way to create a vector with each participant code having its own cell?
4 件のコメント
Stephen23
2022 年 1 月 18 日
編集済み: Stephen23
2022 年 1 月 18 日
"... when I want it to return [MH, TM, JW]"
In MATLAB square brackets are a concatenation operator, not a list operator like in some other languages.
What you need is a cell array, just as Benjamin shows: https://www.mathworks.com/help/matlab/cell-arrays.html
You might find these informative too: https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html
採用された回答
Voss
2022 年 1 月 18 日
Maybe this?
folder_names = struct('name',{'a','bb','ccc'})
participant_ID = {folder_names.name}
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!