String Comparisons in Tables

4 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2022-11-26
if strcmp(ImportDataGeom(i,1),"CircleR"+i)
When you use () indexing of a table, the result is a table. Use {} instead.
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by