Delete entire rows based on one condition
이전 댓글 표시
Hello,
I am a beginner in Matlab. I have a table that has 7 columns and 240 rows.
I need to delete entire rows based on the following condition:
1. if a value of column 7 is superior than 1000 and inferior than 100 => delete this row
I have attached an image of how the datset looks like. Please help!
답변 (1개)
Hi,
Try this:
data = num2cell(randi(5000,240,7)); % sample random data in a cell array
my_Table = cell2table(data); % convert cell array to table
new_table = my_Table(~(my_Table.data7 > 1000 | my_Table.data7 < 100),:); % filter and remove
댓글 수: 11
Image Analyst
2019년 12월 5일
Try again -- he want to delete those rows, not extract (keep) them.
Khayroon Suleyman
2019년 12월 5일
Luna
2019년 12월 6일
Made a small change. Can you check again?
Khayroon Suleyman
2019년 12월 6일
Khayroon Suleyman
2019년 12월 6일
Khayroon Suleyman
2019년 12월 6일
Luna
2019년 12월 6일
I think we have some misunderstanding here.
- You should define variable names while using cell2table. If you do not define them, Matlab autogenerates variable names for you and most probably the variable name will not be TargetexpRT. You should go to your Matlab's Workspace and double click the table to see what are your variable names.
- How did you import your CourseworkFinalDATAEXCEL ? when you run the line CourseworkFinalDATAEXCEL = cell2table(data); this only overrides my randomly created data to your CourseworkFinalDATAEXCEL so you should make an import again.
Here is some tips how to import from Excel:
readtable you should put 'ReadRowNames' input as true to read first column of your excel file as variable names.
Here in your case with your variable names:
CourseworkFinalDATAEXCEL = readtable('CourseworkFinalDATAEXCEL.xlsx','ReadRowNames',true);
new_table = CourseworkFinalDATAEXCEL(~(CourseworkFinalDATAEXCEL.TargetexpRT > 1000 | CourseworkFinalDATAEXCEL.TargetexpRT < 100),:);
Khayroon Suleyman
2019년 12월 6일
Use the fullfile path and name together for example:
readtable('C:\Users\Desktop\...\CourseworkFinalDATAEXCEL.xlsx','ReadRowNames',true);
The path is where your excel file is.
Ayush Jain
2022년 5월 29일
Thanks it worked
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!