How to remove rows in table?

Hello, I need to remove multiple rows in table... I have a table where the first column is imageFilename and there are paths to the images... i need to remove some rows by telling the program exact path... for example i have list of 60 paths which i want to remove from table... how to do this ? thanks for answers

5 件のコメント

Stephen23
Stephen23 2023 年 5 月 8 日
"how to do this"
Probably some text comparison (e.g. MATCHES) followed by some basic MATLAB indexing.
What have you tried so far?
Adrian Kleffler
Adrian Kleffler 2023 年 5 月 8 日
i have tried code like this but it has deleted no 2 images but 200 images ...
% Nahratie tabulky LabelData
load('LabelData.mat');
% Zadanie ciest k obrazkom, ktoré chceš vymazať
pathsToDelete = {'E:\ADRIAN\BAKALARKA\DATASET\vsetko2\panasonic_fullhd_01-090-000-202109092000.jpg', 'E:\ADRIAN\BAKALARKA\DATASET\vsetko2\panasonic_fullhd_01-090-000-202109092200.jpg'};
% Vymazanie riadkov s danými cestami
for i = 1:length(pathsToDelete)
idx = find(strcmp(LabelData.imageFilename, pathsToDelete{i}));
LabelData(idx, :) = [];
end
% Uloženie upravenej tabuľky
save('LabelData.mat', 'LabelData');
Jonas
Jonas 2023 年 5 月 8 日
try
i = length(pathsToDelete):-1:1
instead of
i = 1:length(pathsToDelete)
why?
if you remove e.g. row 3 of a table, then the original row 4 becomes row 3. your for variables the increases by one und checks the 'new' row 4, which is row number 5 in the original table
Adrian Kleffler
Adrian Kleffler 2023 年 5 月 8 日
hello, the code still deletes so many rows... i told him to remove only 5 images and it has deleted from 888 images to 111 images...
Jonas
Jonas 2023 年 5 月 8 日
could you provide your LabelData.mat please

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2023 年 5 月 8 日

0 投票

Try this (untested):
% Nahratie tabulky LabelData
load('LabelData.mat');
% Zadanie ciest k obrazkom, ktoré chceš vymazať
pathsToDelete = {'E:\ADRIAN\BAKALARKA\DATASET\vsetko2\panasonic_fullhd_01-090-000-202109092000.jpg', 'E:\ADRIAN\BAKALARKA\DATASET\vsetko2\panasonic_fullhd_01-090-000-202109092200.jpg'};
% Vymazanie riadkov s danými cestami
numRows = height(LabelData)
rowsToDelete = false(numRows, 1);
for k = 1 : length(pathsToDelete)
thisPath = pathsToDelete{k};
% Check every row in the table for this path.
for k2 = 1 : numRows
if strcmpi(LabelData.imageFilename{k2}, thisPath)
rowsToDelete(k2) = true;
end
end
end
% Delete the rows we need to
LabelData(rowsToDelete, :) = [];
% Uloženie upravenej tabuľky
save('LabelData.mat', 'LabelData');
Peter Perkins
Peter Perkins 2023 年 6 月 5 日

0 投票

You don't need loops to do this. Hard to verify that this does what you are asking for with no mat file.
pathsToDelete = {'E:\ADRIAN\BAKALARKA\DATASET\vsetko2\panasonic_fullhd_01-090-000-202109092000.jpg', 'E:\ADRIAN\BAKALARKA\DATASET\vsetko2\panasonic_fullhd_01-090-000-202109092200.jpg'};
idx = ismember(LabelData.imageFilename, pathsToDelete{i}));
LabelData(idx, :) = [];

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

製品

リリース

R2023a

質問済み:

2023 年 5 月 8 日

回答済み:

2023 年 6 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by