필터 지우기
필터 지우기

For loop and coordinates

조회 수: 3 (최근 30일)
Davide Cerra
Davide Cerra 2020년 4월 21일
편집: Ameer Hamza 2020년 4월 21일
hello,
the gencircle function generates the coordinate for an inscript polygon. But off course in the for loop i obtain only the last iteration. how can i store the results of each loop in a matrix?
xo=[1 2];
yo=[-1 -0.5];
r=0.01;
N=10;
theta=2*pi/N*(1:N+1);
th=0.00235;
for i=1:length(xo)
[xout, yout]=gencircle(xo(i),yo(1),r,N);
[xin, yin]=gencircle(xo(i),yo(1),r-th,N);
end

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 21일
편집: Ameer Hamza 2020년 4월 21일
I don't know the output dimensions of the function gencircle, so I can suggest a general solution using cell arrays. If you know the dimension, a numeric array will also work.
xo=[1 2];
yo=[-1 -0.5];
r=0.01;
N=10;
theta=2*pi/N*(1:N+1);
th=0.00235;
xout = cell(1,length(xo));
yout = cell(1,length(xo));
xin = cell(1,length(xo));
yin = cell(1,length(xo));
for i=1:length(xo)
[xout{i}, yout{i}]=gencircle(xo(i),yo(1),r,N);
[xin{i}, yin{i}]=gencircle(xo(i),yo(1),r-th,N);
end
Access the elements using brace indexing. For example
xout{1} %% xout for i==1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by