Re: How do I optimize the code to make it faster?
- From: Niner <ninerh@xxxxxxxxxxx>
- Date: Sat, 29 Apr 2006 17:37:51 -0400
Roger Stafford wrote:
the
In article <ef33782.-1@xxxxxxxxxxxxxxxx>, Niner
<ninerh@xxxxxxxxxxx> wrote:
Hi,matrix,
I have a question about the 'loop' operation. I have a big
and I want to perform the calculation several times. I use thiscode
to do the job.matrix
-------------------------------
k=1;
for i=0.1:0.1:50
c = i*d;
A = c*B./C;
PL(:,k)=A';
k=k+1;
end
-------------------------------
The code above shows that when given matrix B and C, I can get
A, then I assign the matrix A to the matrix PL as a column. Forconstant. So
example, B and C are 1-D matrix, usually 1x484. c is the
the A should be the matrix of size 1x484. Then I assign it tomatrix
PL as one column: PL(:,k)=A'. Since i=0.1:0.1:50, there are 500
columns in PL. And the PL has size of 484*500. The purpose of
thecode is when given a 'c', there are 484 values resulted from
'c'.
using
My question is, how can I do to perform the calculation without
for-loop? I notice the speed is way too slow if the size ofmatrix B
and C is increasing, and if the range i is increasing. I knowthat if
I only use the 'matrix way', like A=c*B./C;, to calculate, theMatlab
just runs in a flip. So I am asking if anyone knows how toaccelerate
the operation like this code?-------------------------
Any feedback is welcome. Thank you very much for your help.
Niner
PL = (B./C).'*[0.1*d:0.1*d:50*d];
(Remove "xyzzy" and ".invalid" to send me email.)
Roger Stafford
Thanks a lot, Roger. You solved my question. Much appreciate. But
here I have another similar question. This time the matrix is using
add/minus sign.
A = d*i + B./C % d is a constant, and i=0.1:0.1:50
The result matrix PL still has size of 484x500. For a given i, I can
get a matrix of 1x484. Now I have i ranging from 0.1 to 50. How can I
use the same concept you mentioned in this calculation? Thanks a lot
for your help.
Niner
.
- Follow-Ups:
- Re: How do I optimize the code to make it faster?
- From: Roger Stafford
- Re: How do I optimize the code to make it faster?
- References:
- How do I optimize the code to make it faster?
- From: Niner
- Re: How do I optimize the code to make it faster?
- From: Roger Stafford
- How do I optimize the code to make it faster?
- Prev by Date: Smooth interpolation for sparce data set from a gridded data set
- Next by Date: Re: left adjusting the matrix with unique elements
- Previous by thread: Re: How do I optimize the code to make it faster?
- Next by thread: Re: How do I optimize the code to make it faster?
- Index(es):
Relevant Pages
|