フィルターのクリア

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 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