From: Sepehr Sadighpour on
Hi. I am trying to create a three-dimensional array using the following nested for-loop. A note on the wfbm function: it outputs a "random" row vector of length lg. What I want is a 3D matrix called "fbm100" that has a 1000 rows of these length lg vectors, and a "depth" or third dimension of "Hsize" as defined below.

I've commented on the line where I'm receiving the error in running this script:

lg=100; %length of pseudo-random walk%
Hinc = 0.05; Hstart = 0.05; Hend = 0.95; %degree of randomness - variable%
H = Hstart:Hinc:Hend;
Hsize=length(H);
fbm100=zeros(1000,lg,Hsize); %preallocating for speed%

for H = Hstart:Hinc:Hend;
for n=1:1000;
randn('state',1)
fbm100(:,n,H*20) = wfbm(H,lg);
end
end

The error is:

??? Subscripted assignment dimension mismatch.

Error in ==> fbm at 14
fbm100(:,n,H*20) = wfbm(H,lg);

I figured because H is in 0.05 increments starting at 0.05 and going to 0.95, multiplying it by 20 would yield integers that could work as indices for the third dimension of fbm100. Any light you can shed on this would be really appreciated.

Thanks,
Sepehr
From: Roger Stafford on
"Sepehr Sadighpour" <sepehr125(a)gmail.com> wrote in message <hthql9$da0$1(a)fred.mathworks.com>...
>
> I figured because H is in 0.05 increments starting at 0.05 and going to 0.95, multiplying it by 20 would yield integers that could work as indices for the third dimension of fbm100. Any light you can shed on this would be really appreciated.
> .....

That's where you made your mistake! With floating point numbers on any binary machine, they cannot represent .05 exactly, so that upon multiplication by 20, they don't always yield an exact integer. You need to alter your program to use integer indices directly and work out the fractional quantities from those indices.

Roger Stafford
From: us on
"Sepehr Sadighpour"
> for n=1:1000;
> randn('state',1)
> fbm100(:,n,H*20) = wfbm(H,lg);
> end

others have shown you solutions to your problem...
just another thought:
- do NOT call
randn('state',1);
in a loop(!)...
- there have been a number of posts in this NG dealing with this;
look for rand/state/etc...

us
 | 
Pages: 1
Prev: display wavelet decomposition
Next: HOLA