**double for loop**Hi,
I am trying to modify the content of a 2D for loop using a double for loop. But the result I am getting is always 0 in the loop i am getting... I am not really too sure of the problem. Can anyone help?
Thanks
example2.vi:
http://forums.ni.com/attachments/ni/170/215997/1/example2.vi
...

**double loop**
Dear All,
I cleared up the notebook but when I plot the picture I don't recover the
contour plot desidered. The colours should be the different correlation
coefficient and it is not the case.
I will be grateful if you could help
Maria
h=0.71
ckms=299792.5
HubE[z_,Om_,Ol_]:=SQRT(Om*(1+z)^3+Ol)dL[z_,Om_,Ol_,h_]:=3.0856*1018*106*ckms/(100*h)*(1+z)*NIntegrate[1/HubE[z,Om,Ol],{z,0,z},MaxRecursion
->100]
TabOmegalambda=Table[i,{i,0.1,1.1,0.05}]
TabOmegaM=Table[i,{i,0.0,1.0,0.05}]
LxOmegalambda={};
Do[
Ol=TabOmegalambda[[k]];
LxOmegaM={};
Do[
Om=TabOmegaM[[...

**double loop do**Dear Mathgroup,
I have a problem with a double loop. Formally it doesn't give any error message but it doesn't let Om variate in the loop, it takes only the first value 0.1.
This is the code
ckms=299792.5HubE[z_,Om_]=(Om*(1+z)^3+(1-Om))^1/2dL[z_,Om_,h_]:=3.0856*1018*106*ckms/(100*h)*(1+z)*NIntegrate[1/HubE[xh=0.71TabOmegaM=Table[j,{j,0.0,1.0,0.01}]
LxOmegaM={};
Do[
Om=TabOmegaM[[j]];
DataGood={};
Do[
logTarest=DataGRB[[i,7]];
logTaErrrest=DataGRB[[i,8]];
Fx=DataGRB[[i,3]];
FxErr=DataGRB[[i,4]];
idGRB=DataGRB[[i,1]];
DataGRB[[i,2]];
class=DataGRB[[i,12]];
beta=Dat...

**double for loop**Hi,
I have three large matrices, one for the x position, one for the y position and one for the z value.
Ideally, I need to extract each value, i.e. x=X(1,1) y=Y(1,1) and z=Z(1,1) and to 3D plot all of the values extracted.
I think a double for loop would be good,
for f = 1:480 & d = 1:752
etc. but this doesn't work.
Thanks.
"tommy Owen" <jesse9021074@hotmail.co.uk> writes:
>I think a double for loop would be good,
Start matlab and type
help for
at the prompt. You'll see an example of the kind of thing
you're trying to do.
...

**30% faster for-loop when changing loop variable from default(double) to int**When testing a very simple program and trying to change the for-loop variable from double to int (Why did I do that?), I found the program becomes faster, about 30%.
The program is as following:
function k=pbug_d(N)
p=0.3;
for i=1:N
p=3.4*(p*(1-p));
end
k=p;
end
On my PC (Pentium 6700, Win7, MatlabR2010b), the command
tic, pbug_d(1e9),toc
took 9.3s.
When I changed the for-loop variable to int type:
function k=pbug_i(N)
p=0.3;
i=int32(1);
for i=1:N
p=3.4*(p*(1-p));
end
k=p;
end
the c...

**double for loop #2**Can someone explain to me the mechanics for a double for loop?
[x,y] = size(z)
for ii = 1:x;
for jj = 1:y;
newz = z(ii,jj)
end
what is the sequence being played out? A geometric interpretation would be good.
"cwc" wrote in message <l0k71e$5g7$1@newscl01ah.mathworks.com>...
> Can someone explain to me the mechanics for a double for loop?
>
> [x,y] = size(z)
>
> for ii = 1:x;
> for jj = 1:y;
>
> newz = z(ii,jj)
>
> end
>
> what is the sequence being played out? A geometric interpretation would be good.
The ...

**How to speed this double for loop up?**Hi, i have one newbie question
If i have a matrix xdim*ydim*3, and i want to make a vector (xdim*ydim)*5,
how can i write it more compact ad spped it up?
Tnx
k=1;
for i=1:xdim
for j=1:ydim
vector(k,:)=[i j mat(i,j,1) mat(i,j,2) mat(i,j,3)];
k=k+1;
end
end
So how to write this in a mor simple way?
% Sample data
x = 2; y = 4; z = 3;
mat = reshape(1:x*y*z,x,y,z);
% Algorithm
[X,Y] = ind2sub([x,y],1:x*y);
matP = permute(mat,[3 1 2]);
vector = [X' Y' reshape(matP(:),3,[])'];
tnx mate :-)
"Trevor" <trevbassNOSPAM@hotmail.com> wrote in message
news:ef5d2...

**double loop optim**hi,
-----------
#include <iostream>
#include <omp.h>
int main()
{
const double p0 = 0.51;
const double p1 = 0.49;
const int N = 100000;
double opt[N];
for (int i=0; i<N; i++)
opt[i] = i;
const double t0 = omp_get_wtime();
for (int ts=N-1; ts>0; ts--)
for (int i=0; i<ts; i++)
opt[i] = p0*opt[i] + p1*opt[i+1];
const double t1 = omp_get_wtime();
std::cout<< t1-t0 <<std::endl;
}
-----------
I use the intelc++ compiler and build it with
icpc -xT -O3 -openmp -o 2 2.cpp
I have a xeon core2duo (SSSE3) L2 2M cache
Is there a particular SSE? instruction...

**speed up double for loop**Hi there,
I am a newbie for matlab and I wish that I can get some
help on this question...
for c=1:n
for d=c+1:n
if Dist(c,d)<= max_dist
edge_matrix(c,d)=1;
edge_matrix(d,c)=1;
end
end
end
where max_dist= predefined constant
Dist = previous matrix that has been calculated
edge_matrix= matrix with 1's and 0's
Is there anyway I can speed up this without the double for
loop? Thank you in advance...
"Wen Pinn Yee" <wpyee11@mathworks.com> wrote in message
&l...

**double for loop #3**Can someone explain to me the mechanics for a double for loop?
[x,y] = size(z)
for ii = 1:x;
for jj = 1:y;
newz = z(ii,jj)
end
what is the sequence being played out? A geometric interpretation would be good.
On 9/9/2013 5:20 AM, cwc wrote:
> Can someone explain to me the mechanics for a double for loop?
>
> [x,y] = size(z)
>
> for ii = 1:x;
> for jj = 1:y;
>
> newz = z(ii,jj)
>
> end
>
> what is the sequence being played out? A geometric interpretation would be good.
>
There is matrix z with x rows and y columns.
The l...

**Double break out of a loop**Hi, I have a real easy question for you experts ;)
I want to break out of two loops...is there a way of doing this without
using flags?
eg.
while(true){
while(true){
break; break;
}
}
Thanks for your help.
Noodle wrote:
> Hi, I have a real easy question for you experts ;)
>
> I want to break out of two loops...is there a way of doing this without
> using flags?
>
> eg.
>
> while(true){
> while(true){
> break; break;
> }
> }
>
>
> Thanks for your help.
>
done: while (true) {
while (true) {
break done;
...

**Avoid double for loop**Any ideas how I reduce this double for loop?
T = 40;
price = rand(T,1);
strike = rand(T,1); %%I know i can generate both of them
simultaneously but this is just a snippet to give you an
idea of what I want to do...
for i=1:T
for j=1:T-1
intrinsic(i,j) = price(j+1)-price(i);
end
end
In article <fnsqle$s8j$1@fred.mathworks.com>,
Anish Goorah <anish.goorah@gmail.com> wrote:
>Any ideas how I reduce this double for loop?
>T = 40;
>price = rand(T,1);
>strike = rand(T,1); %%I know i can generate both of them
>simultaneously but this is just a snippet t...

**how to avoid a double for loop**Hello everyone,
I have a matrix A of 1 and 0's and I would like to know the indices of
any two columns that are either equal, or which are identical except
one column has zeros where the other has 1's and vice versa. (the
background is that these are cues for questions, and I would like if
there are identical questions, so that one of them is useless).
Now I do this with two for loops, going through all columns pairwise
and I would be very grateful if someone has an idea how this can be
done more effectively!
Here my loop:
for i = 1: m-1
for j = i+1:m
...

**how to get out of double for loops?**Hi all,
I want to quit of both "for" loop whenever I find x[i][j]=1;
Do you know how to do it?
Right now, I am using the following code but I believe there should be
a much more efficient way for this task.
flag=0;
for (i=0;i<H;i++)
{
for (j=0;j<H;j++)
if (x[i][j]==1)
{
flag=1;
break;
}
if( flag)
break
}
Thanks
MBALOVER <mbalover9@gmail.com> writes:
>I want to quit of both "for" loop whenever I find x[i][j]=1;
>Do you know how to do it?
...

**Why double paranthesis in for loop?**All, in the alternate form of the for loop, why do we need a double
paranthesis? What's the rationale behind this?
Ex:
for ((i=0; i<5; i++)); do echo $i; done
TIA,
Sashi
In bash, we use $((...)) to evaluate arithmetic condition, ((...)) is
very similar to $((...)), but neater and more efficient.
Xicheng
Sashi wrote:
> All, in the alternate form of the for loop, why do we need a double
> paranthesis? What's the rationale behind this?
> Ex:
> for ((i=0; i<5; i++)); do echo $i; done
> TIA,
> Sashi
Sashi wrote:
> All, in the alternate form of the for loop, w...

**Double Variable Loops!??!?!?!**I was curius if you could make a double, triple, or more variable
loops!??! and if you can loop a transpose?
1st- is something like this possible??
for i= 1:10;
eval(sprintf('a%d = b%d * c%d;',i))
end:
In my mind each %d is 1...2....3....4 and at the same time thus
a1=b1*c1, a2=b2*c2, and so on....to a10=b10*c10. Where b1,c1, etc...
are already made files.
or does something like this just not work?
2nd- can I loop a transpose???
for i=1:10;
eval(sprintf('a%d = b%d';',i));
end;
i.e. the 2nd ' is for the transpose but matlab doesn't take it that
way so is there ...

**how to vectorize a double loop**Hi There,
How do you vectorize this code?
for i=n:-1:1
for j=1:(2*i-1 )
s(j) = s(j)*edx;
C(j) = max(disc*(pu*C(j)+pm*C(j+1)+pd*C(j+2)),K-s(j));
end
end
Thanks
Dear Luigi!
> How do you vectorize this code?
>
> for i=n:-1:1
> for j=1:(2*i-1 )
> s(j) = s(j)*edx;
> C(j) = max(disc*(pu*C(j)+pm*C(j+1)+pd*C(j+2)),K-s(j));
> end
> end
dpu = disc * pu;
dpm = disc * pm;
dpd = disc * pd;
for i=n:-1:1
s = s .* edx;
KminusS = K - s;
d = 2*i-1;
C(1:d) = max(dpu * C(1:d) + dpm * C(2:d+1) + dpd * C(3:d+2), ...
...

**speed up double loop**Hello, every body, I want to accelerate my numerical kernel
within cauchy principal, and then to take this as kernel
into ode45, however due to its divergence case happend
inside kernel I have to skip special point and set
conditions inside the kernel. Briefly speaking this is a N
by N matices with conidtional diagonal terms. So can anyone
do me a favor for how to optimize this kenel by vector,
thank you very much. The kernel is listed as follows
ychy=zeros(N,1);
y1c=zeros(N,N);
for k=1:N
for j=1:N
if ( j~=k )
y1c(k,j)=(y(j)-y(k)+y(N+j)-y(N+k))./(E(j)-E(k));
...

**Comparing double in for loop**Hi all,
i have encountered the strangest behavior. Check out this simple
program:
#include <stdio.h>
int main()
{
double time = 1;
double i = 0;
for (double i = 0; i < time ; i+=0.01 )
{
if ( i == 0.15 )
{
printf( "found %f\n", i);
}
if ( i < 0.1 )
{
printf( "foundXX %f\n", i);
}
}
return 1;
}
What would you expect to be printed:
All the numbers from 0.0 to 0.9 with the prefex: foundXX
and last line in output should be found 0.15 - right?!
Wrong... what I get is all the numbers from 0.0 to 0.1 printed
(inclu...

**double for loop problem**Hi Guys, sorry to bother you with a stupid question, but I'm struggling here,... I have two arrayes with nn- number of columns,... in the first array.1 are the "values" and in the second array.2 are the "error for the values in the first array",... i.e. array.1(:,1) and array.2(:,1) belong together,... and i'm trying to make a simple loop which would put the values in one array together with the associated erros in the following way,...
results = array.1(:,1) , array.2(:,1), array.1(:,2), array.2(:,2),..... array.1(:,nn), array.2(:,nn) % i.e. the 1st column from ...

**Aborting from double while loops**Hi,
I am trying to do a X-Y movement with one of my piezostage automatically. It would be required for it to move in x-y direction for a certain user defined steps.
However, I have problem with trying to abort the motion at will. Previously I have used a for loop and I know that there did not exist any stop condition for it and I have switched to a while loop. THe existing program structure has a double while loop with one while loop nested within another one.
HOwever, I have a problem with terminating the program. The program will still fin...

**Problem in double while loop**Hi,
I'm having a problem using double while loop.
I put my program in a while loop where the condition is set to:" continue if true".
this while loop is put in another while loop(as i want the user to interact with the program). The outer while loop is set to constant false and condition stop if true.
i'm having a problem as i'm unable to display the result.
Please help me.
Attached is the diagram. I'musing llabview 7.0.
Thanks.
doublewhileloop.JPG:
http://forums.ni.com/attachments/ni/170/249813/1/dou...

**Avoiding a double for loop**Hi
I am working on a very simple simulation.
The system is represented in a matrix containing numbers
between 0 and 1.
How the system changes over time is described by a weighted
sum of the surrounding numbers (with the edges being constant).
The code looks as follows:
copyS = S;
for i = 2:N-1
for j = 2:N-1
if M(i,j)
S(i,j)=min(sum(sum(w_kl.*copyS(((i-1):(i+1)),((j-1):(j+1))))),1);
end
end
end
Where S is the system (a square matrix), w_kl is the
weighting (a 3 x 3 matrix), N is the length of S, and M is a
matrix which determines i...

**improving a double loop**hi,
does anybody know how can I improve this double loop? so it can run
faster
thanks,
german
for i=1:1000
[x,y] = ind2sub(size(A),B{i});
x=x+LFTRGT;
y=y+UPDWN;
C(i)= mean(A(sub2ind(size(A),x,y)));
for j=1:500
D=img(:,:,j);
E(i,j)=mean(D(sub2ind(size(D),x,y)));
end
end
This code is very odd.
Take this line: C(i)=mean(A(sub2ind(size(A),x,y)));
Now
A(sub2ind(size(A),x,y)) should be same as A(x,y) pretty much
by definition of sub2ind. And moreover, this will return one elementof
A,
so why do you have mean() there?
Can you confirm that this line is equivalent to C(i)=A(...