How to store data to a new column after each iteration.

Hi,
I am looking at some data and each loop I define am sample from this data and the want to store it in a table.
So each time loop I want to add a new column to a table and store the data (so the table would ideally be (x1(1), x2(1), x1(2), x2(2)...etc) , however the length of this data is different each time and that seems to make it more difficult.
Am wondering if theres any obvious way to do this, or just to store it directly into a excel file in this format.
thank you in advance.
m=[];
for x=1:9
FileName= sprintf('A_S_%d.txt', x); %read file
data = importdata(FileName);
t=data(:,1);
d=data(:,2);
Max_Depth= max(d);
[maxvaly,idx] = max(d) ;
Time = t(idx) ;
[val,idx2]=min(abs(d));
minVal=d(idx2);
Time2 = t(idx2) ;
tableA(x,:)=[{x} Time2 minVal Time Max_Depth];
t3 = array2table(tableA, 'VariableNames', {'Repeat','Time_of_Impact_s','Impact_Depth_nm', 'Time_of_Max_Depth_s', 'Max_Depth_nm'});
x1=t([idx2:idx]);
x2=d([idx2:idx]);
% m=[m; t([idx2:idx])];
% m=[m; d([idx2:idx])];
m=[m;x1;x2;]
plot(x1,x2); hold on
title ('Impact Depth From 0 to Max'), xlabel('Time(s)'), ylabel('Impact Depth (nm)')
end

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 3 Jul 2020

Commented:

on 14 Jul 2020

Community Treasure Hunt

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

Start Hunting!