How to delete in a table a row which contains a specific word

Hello, I'm writing to you for this particular modification of my table that I extracted from a long .csv file using the function readtable
I have a very big table of data 56644x8 (some colums are number/coordinates, others contain words).
I'm interested to eliminate the rows which contain the word "Alignment" at the 7th column.
The more difficult step is that I would create a code that recognize words like Allignment, Allignment_test, Alignment_ecc, Alignment2 because I don't know if the input data could change in the future.
I'll appreciate all type of helps, thank you very much
Andrea
Edit: I attached a similar file to mine, hope it will be helpful

 Réponse acceptée

try with this:
A=readtable('andrea_file.csv','ReadVariableNames',false,'HeaderLines',3);
B=table2cell(A);
C=string(B)
C = 2×8 string array
"R" "-0.9" "-94.8" "-9.5" "-2" "-45" "Another_text_i_want_to mantain" "1" "R" "0.5" "5" "-2" "3" "0" "Alignment_Pin" "2"
[row col]=find(C=='Alignment_Pin');
C(row,:)=[]; % eleminating row that contains "Alignment_Pin"
C(:,[2 3])=[] % eleminating column 2 and 3
C = 1×6 string array
"R" "-9.5" "-2" "-45" "Another_text_i_want_to mantain" "1"

Plus de réponses (1)

as you did not attach your file, i have attached my own created data
A=readtable('myfile.xlsx','ReadVariableNames',false);
B=table2array(A);
C=string(B);
[row col]=find(C=='Alignment');
C(row,:)=[];

3 commentaires

Hi Arif, i tried on my file and there's something that probably I didn't notice, because it give me this error
Error using table2array (line 37)
Unable to concatenate the table variables 'R' and 'TIPX', because their types are cell and double.
Error in Import_Matrix_status (line 5)
B=table2array(A);
I'll attach a file similar to mine in order to understand why I can use your code that I used in this way (it's similiar but with headerlines):
clc; clear all; close all;
A=readtable('andrea_file.csv','ReadVariableNames',false,'HeaderLines',3);
B=table2array(A);
C=string(B);
[row col]=find(C=='Alignment');
C(row,:)=[];
My final goal it's to extract the second and third column (they are coordinates X and Y), but first eliminating the row with NTYPE that contains coordinates that I don't want. After all I'll have a simple matrix of only cordinates
Thanks a lot
Andrea
is this your expectation?
A=readtable('andrea_file.csv','ReadVariableNames',false,'HeaderLines',3);
B=table2array(A);
C=string(B);
[row col]=find(C=='Alignment_Pin');
C(row,:)=[]; % eleminating row that contains "Alignment_Pin"
C(:,[2 3])=[] % eleminating column 2 and 3
Error using table2array (line 37)
Unable to concatenate the table variables 'Var1' and 'Var2', because their types are cell and double.
Error in Import_Matrix_status (line 5)
B=table2array(A);
Hi, using that code fives me this (the same) error.. I think the problematic is the command "table2array" that is not permitted..Maybe I can work directly on the table A to elimate row bypassing B?
Thanks

Connectez-vous pour commenter.

Catégories

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by