I have two Arrays of multiple numbers lets call it X and Y. I Need to make another array of numbers displayed as cordinates. So let's say that X[150 200 300 500] and Y[300 500 800 300] I need an array like [150,300 200,500 300,800 500,300]. the purpose is then to copy the data and paste to Autacad to make a polyline. Is there a simple way to do this ? I appriciate any kind of help.

 採用された回答

Michael
Michael 2021 年 6 月 2 日

0 投票

Simple in Matlab
X = [150 200 300 500]';
Y = [300 500 800 300]';
coords = [X,Y]
coords =
150 300
200 500
300 800
500 300

6 件のコメント

Þorfinnur Karl Magnússon
Þorfinnur Karl Magnússon 2021 年 6 月 2 日
Thanks alot but. the X and Y data for one variable needs to be printed in one column with the comma in between so the fyrst array should be printed as 150,300
Michael
Michael 2021 年 6 月 2 日
You are looking for a string output, not numeric?
Michael
Michael 2021 年 6 月 2 日
I am going to assume you are looking for a string output. Here is how I would do it.
X = [150 200 300 500]';
Y = [300 500 800 300]';
thematrix = [X,Y]';
asvector = thematrix(:);
stringvector = num2str(asvector);
comma_vector = repmat(', ',1,numel(X))';
blah = [stringvector,comma_vector]';
XY = ['[',blah(1:end-1),']']%end-1 is to get rid of last space
This would produce the output:
XY = '[150,300 200,500 300,800 500,300]'
Þorfinnur Karl Magnússon
Þorfinnur Karl Magnússon 2021 年 6 月 2 日
Thanks alot ! Is there any way to print the resault in a new row ? just to make it more neat :D for example
XY =
150,300
200,500
300,800
500,300
Michael
Michael 2021 年 6 月 2 日
Add a new line character and use the fprintf command:
X = [150 200 300 500]';
Y = [300 500 800 300]';
thematrix = [X,Y]';
asvector = thematrix(:);
stringvector = num2str(asvector);
comma_vector = repmat(',\',1,numel(X))';
return_vector = repmat(' n',1,numel(X))';
blah = [stringvector,comma_vector,return_vector]';
%XY = ['[',blah(1:end-1),']']
fprintf(blah(:)')
Produces this in the command window:
150, 300
200, 500
300, 800
500, 300
Please remember to accept this answer.
Þorfinnur Karl Magnússon
Þorfinnur Karl Magnússon 2021 年 6 月 2 日
Thank you for the help sir I greatly appriciate it :D

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by