Array from structs in a workspace
显示 更早的评论
Good day.
I’m a little bit mixt up with chars, doubles, operands, and so on…
1st. I’m loading a bunch of structs from directory to workspace.
files=dir('C:\...\*.mat');
for i=1:length(files)
load(files(i).name);
end
I want to make from them an array.
array=[name1 name2 ... name118]
This method produces expected outcome – a struct 1x118. The only undesirable thing is to type all the 118 names “manually”.
I trade some “shortcuts”…
array = files;
Produces incorrect array 118x1 with some data about files, not their fields.
array =(files(i).name);
Asks to check for missing argument or incorrect argument data type in call to further function 'struct2cell'.
array =(1:files(i).name);
Error due to colon operator with char operands, first and last operands must be char.
Search in manuals and “ask” section is still in progress. Who – also can't fit, because at that point of the script are additional/not .mat variables (files and i) in workspace.
Maby someone has a hint on how I could avoid typing in “manual”?
2 个评论
Walter Roberson
2020-8-16
Do each of the files have exactly the same variable names in exactly the same order?
Andrew
2020-8-16
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!