Can this loop be avoided?

classic Classic list List threaded Threaded
4 messages Options
Richard llom Richard llom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Can this loop be avoided?

Hello All,
I have this for loop:
for i=1:size(log_data,'r')-1
    energy(i)=(log_data(i+1,1)-log_data(i,1))*log_data(i,2)*log_data(i,3);
end

The rows / loopsize are only a couple of thousands, so it is not that big of deal, still I was wondering: It is possible to do this w/o a loop?

cheers
jasper van baten jasper van baten
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can this loop be avoided?

try

index=1:size(log_data,'r')-1;
energy=(log_data(index+1,1)-log_data(index,1)).*log_data(index,2).*log_data(index,3);

Best wishes,

Jasper.



On 8/1/2017 13:00, Richard llom wrote:
Hello All,
I have this for loop:
for i=1:size(log_data,'r')-1
    energy(i)=(log_data(i+1,1)-log_data(i,1))*log_data(i,2)*log_data(i,3);
end

The rows / loopsize are only a couple of thousands, so it is not that big of
deal, still I was wondering: It is possible to do this w/o a loop?

cheers



--
View this message in context: http://mailinglists.scilab.org/Can-this-loop-be-avoided-tp4036792.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra Rafael Guerra
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can this loop be avoided?

In reply to this post by Richard llom
Schlumberger-Private
Try this:
energy = ( log_data(2:$,1) - log_data(1:$-1,1) ).*log_data(1:$-1,2).*log_data(1:$-1,3);

-----Original Message-----
From: users [mailto:[hidden email]] On Behalf Of Richard llom
Sent: Tuesday, August 01, 2017 1:01 PM
To: [hidden email]
Subject: [Scilab-users] Can this loop be avoided?

Hello All,
I have this for loop:
for i=1:size(log_data,'r')-1
    energy(i)=(log_data(i+1,1)-log_data(i,1))*log_data(i,2)*log_data(i,3);
end

The rows / loopsize are only a couple of thousands, so it is not that big of
deal, still I was wondering: It is possible to do this w/o a loop?

cheers



--
View this message in context: http://mailinglists.scilab.org/Can-this-loop-be-avoided-tp4036792.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Richard llom Richard llom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can this loop be avoided?

In reply to this post by Richard llom
Thanks Jasper & Rafael, these solutions work great!
Loading...