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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!