Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
can this code be sped up?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a short program to take x-y-z (position position value) data and turn it into a matrix and then make a filled contour plot with it, i have large data sets (finished matrix is 1560 x 78). The data is listed with a fixed y for 1560 points with a changing x and z measurement, then that is repeated 77 more times with a different y. The code takes atleast 68 seconds to run depending on which computer i run it on. I was wondering if there is a way to change the code to speed it up. here is the code.
ifilename = uigetfile;
data=importdata(filename);
Matrixform=data.data;
x=Matrixform(:,1);
y=Matrixform(:,2);
z=Matrixform(:,3);
i=1;
m=length(unique(y));
n=length(unique(x));
yl=length(y);
for i=1:m;
j=1;
for j=1:n;
Mat(j,i)=z(j+n*(i-1));
end
end
[c,h] = contourf(Mat,200);
I have tried using meshgrid and griddata but the plot was smoothed too much ( i tried linear and cubic variations). i dont want to lose any detail from my data. thanks in advance
댓글 수: 0
답변 (3개)
Sean de Wolski
2011년 6월 17일
Mat = zeros(n,m);
before the two for-loops will speed this up immensely for large [m n].
Also, you don't need to set j=1 in the first for-loop, this is done automatically on the initialization of the inner loop.
댓글 수: 0
Robert Cumming
2011년 6월 17일
you dont appear to initialize your Mat variable, i.e.
Mat = zeros(n,m)
This should make a big difference to start with
댓글 수: 0
Andrew Newell
2011년 6월 17일
You could replace the double loop by
Mat = reshape(z,n,m);
EDIT: I'll bet most of the time is spent calculating 200 contours. You could try
imagesc(Mat)
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!