Transforming a cell array into a table, rotating it a 90 degree and deleting particular rows
Show older comments
Hey dear Matlab-Knowers, I'm desperate ...
What I got: a cell array with 4x18622 cells. Within the first two lines I have int variables (the ID of my object and the state of it), in the 3rd and 4th I have a date and time stamp.
What I want: I want to reorganize my data the way, that I can handle it in a table. Bc later on I have to do calculations with it. Besides this I have to filter/delete those rows, in which I have a particular number in the second line.
What I did so far: So what I basically tried - and succeeded in, was taking the cells (at least the second line, because there I'm able to find my elimination parameter) and delete each row with a '2' as value. I did this with the help of an if-loop within a while-loop ... Only until I realized, that this is only half of what I have to do - missed out to also delete the "rest of the row" part of line 1, 2 and 3 ... yay ... and I'm not sure how to handle those time variables.
What I ask you:
- How to not only transform this array into a table (I know there exists the function 'cell2table' ..) but also turn it around so I got a 18622x4 table.
- Perfect would be, if I could also name my rows according to my classes (ID, State, Time, Date)
I rlly appreciate every help I get!! Best regards ...
Accepted Answer
More Answers (1)
Guillaume
on 12 Jul 2018
%note the ' below to transpose the 4xN cell array into a Nx4 cell array
t = cell2table(yourcellarray', 'VariableNames', {'ID', 'State', 'Time', 'Date'})
%delete rows of table whose state is 2:
t(t.State == 2, :) = []
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!