How to use writetable in a for loop
13 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I want to write a script that, for all files in my folder, selects a specific value out of a table and puts them together in one new table. I am using a for loop including the writetable command, but it creates a new file containing only the value of the last iteration. What am I doing wrong?
volumeTable = dir('*properties_aparc.mat') %% here I select the files I need out of my folder
for k = 1:length(volumeTable);
baseFilename = volumeTable(k).name;
fullFilename = fullfile(volumeTable(k).folder,baseFilename);
load(fullFilename);
T = regionPropertiesTable(31,4) %% Select row 31, column 4 from the regionPropertiesTable
writetable(T)
end
When I use regionPropertiesTable(x,y) outside of this code, it gives me a 1x1 table. I want to add the 1x1 tables of all my participants together into one file (.txt is fine).
Thanks in advance for your time! I am relatively new to MatLab.
0 个评论
采纳的回答
VBBV
2022-3-25
T{k} = regionPropertiesTable(31,4)
Use a cell array for all participants. Later use
writetable(T)
Outside of loop
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!