Split table at n rows and plot data
Show older comments
I have a rather large .txt file (attached is an abbreviated version), there are about 500 cycles in the full file. Column 1(Var1) is the row count which is not always consistent, meaning sometimes it ends the cycle at the same row count, and other times it is different.
I used the text indicator on Var28, to split the table into 'Extend' and 'Retract' cells and then removed the Var28 string to make plotting easier. I need to plot each cycle Extend and Retract and find the min/max values and compare them with a specific value to see if they are in tolerance.
My question is, is there an easier way to do this rather than what I have started to do...? Matlab version: 9.2.0.556344 (R2017a)
% Test Run
clc
clear
%% Import Data
T = readtable('TestFileData.txt');
T(:,28) = [];
%% Split table using mat2cell
V = [8 6 9];
C = mat2cell(T,V,size(T,2));
% C{:,:} % to get all of the data
% C{1,1} Gives the first table (8x28 table)
E1 = C{1,1};
newE1 = table2array(E1); % convert table E1 to an array so we can plot
minVar17 = min(newE1(:,17));
maxVar17 = max(newE1(:,17));
% C{2,1} Gives the second table (6x28 table)
R1 = C{2,1};
% C{3,1} Gives the third table (9x28)
E2 = C{3,1};
%% Plot data
% Extend 1
x = newE1(:,2); % Column 2 i.e. time
yy1 = newE1(:,17); % Column 17
yy2 = newE1(:,18); % Column 18
plot(x,yy1,x,yy2)
title('Var17/18')
xlabel('Time(s)')
ylabel('Pressure(psig)')
grid on
legend(
'Var17','Var18','location','best')
I have added a PNG of the txt file I was using, right now I'm just using simulated data.
4 Comments
dpb
on 7 Jun 2019
Your attached file doesn't show any text input columns???
Probably you can do what you want with findgroups and splitapply directly or with similar operations if start with the indicator variable(s) that define the groups desired...but can't see that in the data file to figure out what is that really want...
Using meaningful variable names for the table would undoubtedly help...
dpb
on 7 Jun 2019
That's totally illegible; attach the beginnings of the text file itself...we can't try to solve your problem unless we have some way to generate an input that at least mimics the problem trying to be solved... :)
Cody Brant Watson
on 8 Jun 2019
dpb
on 8 Jun 2019
The issue was I couldn't begin to read the image to make out what it was...and, I first couldn't find the text in the last column in the text file because of the line wrap issues...
Accepted Answer
More Answers (0)
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!