String Comparisons in Tables

1 view (last 30 days)
Aqib Memon
Aqib Memon on 26 Nov 2022
Commented: Aqib Memon on 27 Nov 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

Accepted Answer

Walter Roberson
Walter Roberson on 26 Nov 2022
if strcmp(ImportDataGeom(i,1),"CircleR"+i)
When you use () indexing of a table, the result is a table. Use {} instead.
  3 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!