フィルターのクリア

String Comparisons in Tables

2 ビュー (過去 30 日間)
Aqib Memon
Aqib Memon 2022 年 11 月 26 日
コメント済み: Aqib Memon 2022 年 11 月 27 日
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 件のコメント
Aqib Memon
Aqib Memon 2022 年 11 月 27 日
@Walter Roberson Thanks works perfectly
Aqib Memon
Aqib Memon 2022 年 11 月 27 日
@Voss thanks to you too

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData 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