Borrar filtros
Borrar filtros

String Comparisons in Tables

2 visualizaciones (últimos 30 días)
Aqib Memon
Aqib Memon el 26 de Nov. de 2022
Comentada: Aqib Memon el 27 de Nov. de 2022
Hello!
I am trying to extract some data from a text file.
The text file contains the centers of the circles and their radius. it also contains some information about points.
The question is, I need to extract the x and y points of each of the circles and points in the text file.
I am using strcmp to compare the strings in table to Circle1, Circle2 etc but its gives logical answer of 0 everytime.
I am not sure how else I can make this work.
Thanks
I have attached my code and the text files I am working with.
ImportDataGeom=readtable("DataGeom1.txt")
ImportDataBis=readtable("DataBis1.txt")
R=size(ImportDataGeom,1);
L=size(ImportDataBis,1);
for i=1:R
if strcmp(ImportDataGeom(i,1),'Circle'+i)
CircleX(i)=table2array(ImportDataGeom(i,2))
CircleY(i)=table2array(ImportDataGeom(i,3))
% th = 0:pi/50:2*pi;
% x_circle = app.CircleR(1,app.NumberOfTimesButtonHitC+1) * cos(th) + DataImport(i,2);
% y_circle = app.CircleR(1,app.NumberOfTimesButtonHitC+1)* sin(th) + DataImport(i,3);
% plot(app.UIAxes,x_circle,y_circle,'LineWidth', 2)
end
if strcmp(ImportDataGeom(i,1),"CircleR"+i)
CircleR(i)=table2array(ImportDataGeom(i,2));
end
if strcmp(ImportDataGeom(i,1),"Points"+i)
PointsX(i)=table2array(ImportDataGeom(i,2));
PointsY(i)=table2array(ImportDataGeom(i,3));
end
if strcmp(ImportDataGeom(i,1),"CircumferencePoint"+i)
CircumferencePointX(i)=table2array(ImportDataGeom(i,2));
CircumferencePointY(i)=table2array(ImportDataGeom(i,3));
end
end
for i=1:L
BisectorX1s(i)=table2array(ImportDataBis(i,1));
BisectorX2s(i)=table2array(ImportDataBis(i,2));
BisectorY1s(i)=table2array(ImportDataBis(i,3));
BisectorY2s(i)=table2array(ImportDataBis(i,4));
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Nov. de 2022
if strcmp(ImportDataGeom(i,1),"CircleR"+i)
When you use () indexing of a table, the result is a table. Use {} instead.
  3 comentarios
Aqib Memon
Aqib Memon el 27 de Nov. de 2022
@Walter Roberson Thanks works perfectly
Aqib Memon
Aqib Memon el 27 de Nov. de 2022
@Voss thanks to you too

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by