How can extract specific value from a column contains 3 conditions

Hello,
I faced problem of separating the data in .csv file. I have huge data consiste of 81 csv, and each file consists of 887808x74 matrix. My work depends on separted 3 conditions (labels) based on third column which has condition 1 , condition 2, and condition 3. I want to put each condition togethor for example condition 1 with all information that related in other columns togethor and so on for other conditions. i tried to do it by myself but not work.
If any one has idea to help me i will appretiate that. it can find out the sample of the file in attachment.
Regards,

 Accepted Answer

I assume that you are using datastore and tall array.
Suppose tb is your tall table. You can use tb1 = tb(tb.(3) == 1, :) to get a subtable that has condition 1 on the third column. and similarly use tb(tb.(3) == 2, :) to get a subtable that has condition 2.
Is this what you want?

4 Comments

what do you mean by datastore?
i apply you suggestion but did not work.
what i want to create sub-matrices based on the three conditions that existed in the main matrix.
using your example file as an example:
tb = readtable('example file.xlsx', 'ReadVariableNames', 0);
tb1 = tb(tb.(3) == 1, :);
tb2 = tb(tb.(3) == 2, :);
tb3 = tb(tb.(3) == 3, :);
If you are not using a table variable, you could easily adjust your syntax using tb(:, 3) == 1 for example. I prefer using table.
thank you for your help , i whish if you can see my problem now ,
i tried the following line of code, sence my file in csv file and i want to work with this extentions
T = csvread('hc.csv');
tb1 = T(T.(3) == 1, :);
it show me an error
[Argument to dynamic structure reference must evaluate to a valid field name.
Error in Readcsv1 (line 21)
tb1 = T(T.(3) == 1, :);]
for that i used used your sggusted code
T = readtable('hc.csv', 'ReadVariableNames', 0);
tb1 = T(T.(3) == 1, :);
it works , but when i tried to save i file into csv file and load it again to matlab dose not work?? by this line
save('tb1.csv');
the message error:
[Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> MATLAB 5.0 MAT-file, Platform:
PCWIN64, Created on: Sat Mar 28 16:49:40 2020 & IM I xϋc``h b6
æ bA`Â0ÍÂàëìd³qIbRN*æb$}¼P}¬P>X/3@ùæ]&...
Error in csvread (line 48)
m=dlmread(filename, ',', r, c);]
please could you help me if the problem clear
thanks,
Using writetable instead to save table to csv or txt or xlsx.

Sign in to comment.

More Answers (0)

Tags

Asked:

on 25 Mar 2020

Commented:

on 28 Mar 2020

Community Treasure Hunt

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

Start Hunting!