필터 지우기
필터 지우기

Please help...

조회 수: 1 (최근 30일)
andy ganteng
andy ganteng 2011년 11월 8일
I have function like this,
function knotident(x,nknot,rand)
clc;
[~,n]=size(x);
for i=1:n
z=x(:,i);
c=min(z);
d=max(z);
if nknot == 1
t=random('unif',c,d,[rand,1]);
else
for g=1:nknot
r=random('unif',c,d,[rand,1]);
t(:,g)=r;
end
t=sort(t,2);
end
kgab(:,i)=t;
end
rand and nknot can be any number. now, i wanna save the result from the loop above for t in matrix with size (rand,nknot*n), but i don't know how to do that. in that syntax i use kgab(:,i)=t; but it cant work if nknot>1. Please help me...
thanks in advance
  댓글 수: 3
andy ganteng
andy ganteng 2011년 11월 8일
aim sorry....i've edit my question...now, please help...
andy ganteng
andy ganteng 2011년 11월 8일
if nknot>1 then matlab said
??? Subscripted assignment dimension mismatch.
Error in ==> knotident at 20
kgab(:,i)=t;

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

채택된 답변

Jan
Jan 2011년 11월 8일
"kgab(:,i)=t;" does not work if t is a matrix.
I've clean up the source a little bit, most of all the repeated computations are move out of the loop:
function knotident(x, nknot, r)
n = size(x, 2);
dim = [r, nknot];
minx = min(x, 1);
maxx = max(x, 1);
kgab = [r, n * nknot]; % Pre-allocate!
if nknot == 1
for i = 1:n
kgab(:, i) = random('unif', minx(i), maxx(i), dim);
end
else % knot > 1
v = 1;
for i = 1:n
t = sort(random('unif', minx(i), maxx(i), dim), 2);
kgab(:, v:(v + nknot - 1)) = t;
v = v + nknot;
end
end
  댓글 수: 1
andy ganteng
andy ganteng 2011년 11월 11일
great...thanks

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

추가 답변 (0개)

카테고리

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