Categories automatically being labelled and sorted into matrix?
Show older comments
I currently have a table that is 635x13. If it says (code) it means I allocated it a number. My data is:
ItemID (code), Date (code), DATA1, DATA2, DATA3, DATA4, DATA5, DATA6,DATA7, DATA8, DATA9, Actual day (day-mon-year), ItemName (words).
- How do I get Matlab to allocate my data an ID number? Can I use the ItemName instead? MatLab seems to get upset about using a written word instead of a number.
- I need to ask Matlab to look at my ItemName, and make a matrix of all the data in the columns by that Item.
Should I be working with the data in a table? Should it be a double? I need to be able to pinpoint the individual Items ideally with words (there are thousands), and the data that corresponds with it.
I tried this:
Item1 = USEFULLDATA0211(USEFULLDATA0211(:,13) == '1', :)
but everytime I try it, MatLab gets upset about it being a cell or as table. I am unsure about how to have all my data in one.
I would love to be able to type in a request to pull the data for X item name, and get all the corresponding data, on all the different days for each.
I have been trying for weeks to solve this now, please explain it to me like I am an idiot.
Thanks :'(
1 Comment
madhan ravi
on 12 Feb 2019
upload your table as .mat file and illustrate with a short example
Answers (2)
Star Strider
on 11 Feb 2019
0 votes
I have no idea what characteristic distinguishes your ‘categories’. See if the findgroups (link) function will do what you want.
2 Comments
Samuel Leathers
on 12 Feb 2019
Star Strider
on 12 Feb 2019
I have no idea what you are doing.
Peter Perkins
on 12 Feb 2019
It's pretty hard to understand exactly what you are trying to do from the information you have provided. One problem with what you have shown is this:
USEFULLDATA0211(:,13) == '1'
You are comparing a (one-variable) table to a char, that won't work. You need to compare the text variable in the table to the char, see the code below. Also, unless ALL of your names are one char, using == will not work, in general with char (single quotes) or cellstr (char inside of cell) you will need strcmp, so I recommend that you use strings (double quotes), again, see the code below.
>> ID = [1;1;2;2;2;1];
>> Data1 = rand(6,1);
>> Date = datetime(2019,2,1:6)';
>> Name = ["aaa";"aaa";"bbb";"bbb";"bbb";"aaa"];
>> t = table(ID,Name,Date,Data1)
t =
6×4 table
ID Name Date Data1
__ _____ ___________ _______
1 "aaa" 01-Feb-2019 0.81472
1 "aaa" 02-Feb-2019 0.90579
2 "bbb" 03-Feb-2019 0.12699
2 "bbb" 04-Feb-2019 0.91338
2 "bbb" 05-Feb-2019 0.63236
1 "aaa" 06-Feb-2019 0.09754
>> t(t.Name == "bbb",:)
ans =
3×4 table
ID Name Date Data1
__ _____ ___________ _______
2 "bbb" 03-Feb-2019 0.12699
2 "bbb" 04-Feb-2019 0.91338
2 "bbb" 05-Feb-2019 0.63236
Categories
Find more on Descriptive Statistics 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!