Effacer les filtres
Effacer les filtres

Please help...

1 vue (au cours des 30 derniers jours)
andy ganteng
andy ganteng le 8 Nov 2011
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 commentaires
andy ganteng
andy ganteng le 8 Nov 2011
aim sorry....i've edit my question...now, please help...
andy ganteng
andy ganteng le 8 Nov 2011
if nknot>1 then matlab said
??? Subscripted assignment dimension mismatch.
Error in ==> knotident at 20
kgab(:,i)=t;

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 8 Nov 2011
"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 commentaire
andy ganteng
andy ganteng le 11 Nov 2011
great...thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by