delete specific rows in a table

조회 수: 4 (최근 30일)
Carlos Alonso
Carlos Alonso 2021년 9월 17일
댓글: Carlos Alonso 2021년 9월 20일
Hi guys, I need your help.
See attached table. I would like to delete the rows in which the first column (time) have a decimal number in it (keep only those rows where the time is an integer number)
After that I would like to delete the rows where the time is repeated and keep only the first one. For example, if there are 3 rows with time 5, we should only keep the top row.
Any help with that?
Many thanks

채택된 답변

the cyclist
the cyclist 2021년 9월 17일
I believe this does what you want. Note that this file doesn't have any repeated integer times. So, you don't need the second step.
% Read in the Excel file
A = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/741684/A.xlsx'); % You can just use 'A.xlsx' here
% Identify the rows that have exact integer time
keepIntegerTimeIndex = logical(abs(A{:,1}==round(A{:,1})));
% Keep only those rows
A = A(keepIntegerTimeIndex,:);
% Verify that there are only unique integer times:
length(A{:,1}) == length(unique(A{:,1}))
ans = logical
1
  댓글 수: 1
Carlos Alonso
Carlos Alonso 2021년 9월 20일
Many thanks, very helpful :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 9월 17일
Try this:
allData = readmatrix('A.xlsx');
times = allData(:, 1);
% Find out where time is a pure integer
goodRows = times - round(times) == 0;
% Extract good rows
times = times(goodRows);
allData = allData(goodRows, :);
  댓글 수: 1
Image Analyst
Image Analyst 2021년 9월 17일
Basically same as the Cyclist. I was working on mine while he was uploading his.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by