how to save coordinates in a text file?

27 ビュー (過去 30 日間)
youssef hany
youssef hany 2022 年 9 月 15 日
回答済み: William Rose 2022 年 9 月 17 日
I've used ''inpolygon'' function and I want to save the red points in a txt file in form of 2 columns of x and y, for ex. :
-1.21 3.24
-1.56 3.52
how can I do that? I'm new to matlab :D
The inpolygon function:
B=readmatrix('points.txt');
xv=B(:,1)';yv=B(:,2)';
p=readmatrix('points1.txt');
xq=p(:,1)';yq=p(:,2)';
[in,on] = inpolygon(xq,yq,xv,yv);
  3 件のコメント
youssef hany
youssef hany 2022 年 9 月 17 日
編集済み: youssef hany 2022 年 9 月 17 日
NO, that's not what I want. I used read matrix to read points from file and then I applied a function (inpolygon) that filters the input data, all I need is to save the filtered points in a text file @Rik
William Rose
William Rose 2022 年 9 月 17 日
@youssef hany, @Rik is offering a hint which sounds good to me. You said "that's not what I want", but since you want to "save the filtered points in a text file", @Rik is right (as usual).

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

採用された回答

William Rose
William Rose 2022 年 9 月 17 日
I do not see the matrix of selected points which you want to save. Maybe that is the problem. Here is an example:
N=100; %total number of points
xq=rand(N,1); yq=rand(N,1);
xv=[.5 .9 .5 .1 .5];
yv=[.1 .5 .9 .5 .1];
in=inpolygon(xq,yq,xv,yv);
plot(xq,yq,'bo',xq(in),yq(in),'rx',xv,yv,'--r');
a=[xq(in),yq(in)];
writematrix(a,'a.txt')
Try that. It should save the coordinates of the selected points as a 2-column text file.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by