MATLAB: Turning cells created with a for loop back to an array by using a for loop after doing calculations on it

cell2arrayfor loop

Hey guys,
when I run this code the following error occurs:
>> FileExtraction_180deg
Error using writecell (line 108)
First argument must be a cell array.
Error in FileExtraction_180deg (line 45)
writecell([timecolumn1{:}], filenameExport ,'Range', 'A5');
As in the code shown below I am extracting certain data from k .dat files. After creating the cells cellcolumn1{k} I do calculations on these extraced data. When I export the data to an excel file afterwards it seems like it is not exporting the processed data but only the raw data. I guess by creating the cells cellcolumn1{k} I am changing the class type of the data which prevents me from exporting them.
Is it possible in some way to export the processed data instead of the raw data? The code works well when I replace timecolumn1 by time1 in the last row of the code shown below.
Thank you very much for your help! 🙂
Best,
Sven
clear all
format long
filenameExport = 'test.xlsx';
b_1 = [1:26];
c_1 = 26;
b_2 = [1:25];
c_2 = 25;
E = 0.059417;
t0_row = 15;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d1_file = cell(1,c_1);
for k = b_1
d1_file{k} = ['OPTP_1_time' num2str(k) '.dat'];
end
%%%%%%%%%%%%
time1 = cell(1,numel(d1_file));
for k = 1
fileID1 = fopen(d1_file{k});
data = textscan(fileID1, '%s %s', 'HeaderLines', 16);
time1{k} = data{1};
fclose(fileID1);
end
timecolumn1 = cell(1,numel(d1_file));
for k = 1
timecolumn1{k} = vpa(time1{k});
end
for k = 1
t0{k} = timecolumn1{k}(t0_row);
end
for k = 1
timecolumn1{k} = timecolumn1{k}-t0{k};
end
writecell([timecolumn1{:}], filenameExport ,'Range', 'A5');

Best Answer

try this
writematrix(double([timecolumn1{:}]), filenameExport ,'Range', 'A5');