How can I extract data from a table and put it into a new one?
Show older comments
Hi!
We made a loop to create a table where all our measurements can be put in. The problem is, that all the measurements are done 4 times(for 1 machine), and we want a new table with the four measurements (from one machine) put in seperate colums.
Our loop looks like this:
files=dir('*.log');
M=NaN(length(files),1);
Lek=M;
B=M;
C=M;
R=M;
PS=M;
TV=M;
For i=1:length(files)
out=textscan(files(i).name,'M%f_Lek%f_B%f_C%f_R%f_PS%f');
A = readcell(files(i).name); %data inladen
Z = string(A);
time = Z(7:end,1); %van time een vector maken
time = strrep(time, ',', '.'); %komma's in vector in punten veranderen
time = str2double(time);
flow = Z(7:end,2);
flow= strrep(flow, ',', '.');
flow = str2double(flow);
flow = flow./60;
flowpos = flow;
flow(flow<0)= 0;
RR=23;
volpos = trapz(time, flow);
TV(i)= (volpos./RR);
TV(i)= TV(i).*1000;
M(i)=out{1};
Lek(i)=out{2};
B(i)=out{3};
C(i)=out{4};
R(i)=out{5};
PS(i)=out{6};
end
T=table(M,Lek,B,C,R,PS,TV,'VariableNames',{'M','Lek','B','C','R','PS','TV'})
If M is 1, we want TV to be in column '1' of the new table, if M is 2, we want TV to be in column '2' of the new table, etc....
How can we do this?
We managed to create a new table just like above, but he wont fill in the TV's.
Thanks in advance, Tessa
Accepted Answer
More Answers (1)
Peter Perkins
on 22 May 2019
0 votes
With no example, it's hard to understand what you have and what you want to end up with, but your description sounds very much like you want to use unstack.
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!