How to save results from each iteration of for loop into one column of an excel

6 次查看(过去 30 天)
Hi, I am fairly new to MATLAB. I wrote the following code to save time stamps of some images located in different folders. The time stamps are as ''2020-06-12_11.56.32'' . I am trying to save these time stamps from each iteration in a single colum but different rows. I tried using writetable for saving ONE iteration, but it breaks down to seperate columns such as:
Time1 Time2 Time3 Time4 Time5 Time6 Time7 Time8 Time9 Time10 Time11 Time12 Time13 Time14 Time15 Time16 Time17 Time18 Time19
2 0 2 0 - 0 3 - 1 2 _ 1 1 . 5 1 . 3 2
How do I save it so the time from each iteration is together on one particular cell instead of breaking it into different columns? Also, how do I save each iteration on the same excel sheet with each results in different rows, such as iteration 1 in row 1, iteration 2 in row 2, iteration 3 in row 3.......?
I would appreciate any help!
D= readtable('A.xlsx');
for i = 1:height(D)
biopsy_folder = char(D.Path(i));
Step2_folder = extractAfter(biopsy_folder, 'Y:');
Step2_folder = extractBefore(Step2_folder,'\Step 3');
Step2_folder=strcat('Z:',Step2_folder);
filename = dir(fullfile(Step2_folder,'MSI_*420*.tiff'));
F= fullfile(Step2_folder,filename.name);
Time= extractAfter(F, '420_');
Time= extractBefore(Time, '.000.tiff')
end
writetable(Time,'Time.xlsx')

回答(1 个)

KSSV
KSSV 2022-2-3
D= readtable('A.xlsx');
T = cell(height(D),1) ;
for i = 1:height(D)
biopsy_folder = char(D.Path(i));
Step2_folder = extractAfter(biopsy_folder, 'Y:');
Step2_folder = extractBefore(Step2_folder,'\Step 3');
Step2_folder=strcat('Z:',Step2_folder);
filename = dir(fullfile(Step2_folder,'MSI_*420*.tiff'));
F= fullfile(Step2_folder,filename.name);
Time= extractAfter(F, '420_');
Time= extractBefore(Time, '.000.tiff')
[filepath,name,ext] = fileparts(Time) ;
T{i} = name ;
end
T = table(T) ;
writetable(T,'Time.xlsx')

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by