Azzera filtri
Azzera filtri

Please help...

1 visualizzazione (ultimi 30 giorni)
andy ganteng
andy ganteng il 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 Commenti
andy ganteng
andy ganteng il 8 Nov 2011
aim sorry....i've edit my question...now, please help...
andy ganteng
andy ganteng il 8 Nov 2011
if nknot>1 then matlab said
??? Subscripted assignment dimension mismatch.
Error in ==> knotident at 20
kgab(:,i)=t;

Accedi per commentare.

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by