how to store the matrix from for loop?

1 回表示 (過去 30 日間)
JAGADEESH JAGA
JAGADEESH JAGA 2017 年 2 月 1 日
コメント済み: JAGADEESH JAGA 2017 年 2 月 3 日
m=3;
A=[ 1 1 0];
B=[0 1 0];
D=B-A;
d1=m*A;
for X=0:1:m
C=d1+D*X
end

採用された回答

KSSV
KSSV 2017 年 2 月 1 日
m=3;
A=[ 1 1 0];
B=[0 1 0];
D=B-A;
d1=m*A;
C = zeros(m+1,length(d1)) ;
for X=1:1:m+1
C(X,:)=d1+D*X ;
end
  1 件のコメント
JAGADEESH JAGA
JAGADEESH JAGA 2017 年 2 月 3 日
the answer is really helpful for me.thanks for the answer. could you answer my question m=3; t=[1 0 0; 0 (1/sqrt(2)) (1/sqrt(2))]; v1=0.24; v2=0.956; a=[ 1 1 0]; b=[0 1 0]; p=b-a; d1=m*a; for x=1:1:m+1 c=d1+p*(x-1) f=transpose(c); vndq=t*f; vnq=vndq(1,1); vnd=vndq(2,1); d(x)=abs(v2-vnq)+abs(v1-vnd) n=min(d) end In the given code c row matrix corresponding minimum value of d matrix must be output if the d changes corresponding c matrix should be abtained to that minimum distance using for loop

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2017 年 2 月 1 日
編集済み: Andrei Bobrov 2017 年 2 月 2 日
m=3;
A=[ 1 1 0];
B=[0 1 0];
D=B-A;
d1=m*A;
C = d1 + (0:m)'*D; % R2016b and later
C = bsxfun(@plus,d1,(0:m)'*D); % R2016a and earlier
  2 件のコメント
Stephen23
Stephen23 2017 年 2 月 2 日
+1 nice use of MATLAB.
Andrei Bobrov
Andrei Bobrov 2017 年 2 月 2 日
Thank you Stephen!

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by