필터 지우기
필터 지우기

store vectors in matrix over for loop

조회 수: 3 (최근 30일)
sita
sita 2013년 5월 10일
Hi,
How to store pairvec(in below code) variable in matrix overnested(ix1,ix2) loops. Pls help me in doing this.
Thanks, SIta
clc;
clear;
x1s=rand(3,1)
x2s=rand(3,1)
for ix1=1:3
for ix2=1:3
pairvec(:,:,ix1*ix2)= horzcat(x1s(ix1),x2s(ix2))
temp=pairvec
end
% finalvec=pairvec(ix1*ix2,:)
end

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 5월 10일
편집: Andrei Bobrov 2013년 5월 10일
x1s=(1:3)';
x2s=(10:10:30)';
[ii jj]=ndgrid(x1s,x2s);
overnested = arrayfun(@(x,y)[x y],ii,jj,'un',0);
or
overnested2 = cat(3,ii,jj);
  댓글 수: 1
sita
sita 2013년 5월 10일
Thanks ...it is helpfull

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

David Sanchez
David Sanchez 2013년 5월 10일
Could you be more precise? Did you realize your pairvec is a 3D array, overnested(ix1,ix2) looks like a 2D array. Did you skip the semicolons (';') at the end of each line on purpose?
  댓글 수: 1
sita
sita 2013년 5월 10일
I am trying to store all combinations of x1s and x2s in pairvec here.I realize that is 3D array. Purposefully i skipped semicolons to observe output on command window .

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by