Hello,
I have 3 column matrix. I want to plot contourf but plot shape is wrong. When i try with patch command shape is true. How can i do this with contourf? Here is example picture.
01.jpg
here is my patch figure code:
a=load('xyz.txt');
x=a(:,1);
y=a(:,2);
m1=a(:,3);
cor=[x y];
ff=reshape( 1:length(cor), 4, length(cor)/4)';
fig = figure;
pm=patch('Faces',ff,'Vertices',cor,'FaceVertexCData',m1,'FaceColor','interp','Selected','on');
colormap(flipud(jet(20)))
shading interp
colorbar
set(pm, 'edgecolor','black','LineWidth',0.5)
grid on
grid minor

댓글 수: 3

Walter Roberson
Walter Roberson 2019년 10월 29일
How are you generating the data for contourf() ?
here is my code for contourf:
xi=linspace(min(x),max(x),300);
yi=linspace(min(y),max(y),300);
[XI YI]=meshgrid(xi,yi);
M1I = griddata(x,y,m1,XI,YI);
figure
contourf(XI,YI,M1I,'edgecolor','none')
colormap(flipud(jet(10)))
shading interp
colorbar
title('X MOMENT','FontSize',14)
grid on
grid minor
this code plots out of boundaries of shape.
Mooner Land
Mooner Land 2019년 10월 30일
Do you have any idea about this my friends?
I am looking forward to your help :)

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 30일

0 개 추천

What you observe is expected for griddata() and other scattered interpolants. You do not have data in a number of areas, but you ask for the values in those areas, so griddata() interpolates from the existing points. By asking for data in those areas but wanting blanks there, you are implicitly saying that lack of data in an area should be treated as-if data were there and was NaN there -- but that somehow the system should know to insert those implicit nans locally, and be smart about it. For example in the place where you have two rectangles touching diagonally, you do not want interpolation between the two rectangles, even though some of those points are closer together than some of the points in the bounds that you do want to influence interpolation.
You will need to segment your data into distinct regions and grid them separately.
For the case you loaded the file for, probably the easiest would be to use an editor to divide into parts.
If you had a number of similar files to process, you can do some processing based upon clustering such as k-means, or using nearest-neighbor-with-cutoff approaches, but automatically dividing out touching diagonal boxes is probably going to take more thought.

댓글 수: 7

Mooner Land
Mooner Land 2019년 10월 31일
Thank you for ypur advices friend :)
I have already group my data as rectangles with accumarray command. In my data above, there are 300 rectangles and i can grup them with accumaaray. After this point i use "for loop" with every group for every rectangle and plot contourf. But this takes a lot of time to get figure and i wait long time for result.
Any advice for making this fast?
Thank you again :)
Walter Roberson
Walter Roberson 2019년 10월 31일
Discretize your coordinates, accumarray() the [y x] indices for first parameter and z as second parameter, with @mean and nan filler. Now contourf() that with appropriate x y coordinates.
Mooner Land
Mooner Land 2019년 10월 31일
i cant understand what i should do :)
here is my data. first column x coordinate, second column y coordinate,third column z coordinate and fourth column is rectangle number. I can make groups witth accumarray using unique elements in the fourth column. After that what should i do?
Thank you for your time and help :)
minx = min(x); miny = min(y);
xidx = round((x-minx)*2) + 1;
yidx = round((y-miny)*2) + 1;
G = accumarray([yidx, xidx], z, [], @mean, nan);
xi = minx + 0.5 * (0:size(G,2)-1);
yi = miny + 0.5 * (0:size(G,1)-1);
contourf(xi, yi, G)
Mooner Land
Mooner Land 2019년 10월 31일
편집: Mooner Land 2019년 10월 31일
thank you friend, the code works for this example but does not gives correct results for another example data. thank for yor all help. :)
Walter Roberson
Walter Roberson 2019년 11월 1일
You could do a morphological dilation on "isnan()" of the array in order to disconnect areas that barely touch.
Mooner Land
Mooner Land 2019년 11월 1일
I am not really good at matlab, so its hard to do this thing. Thank you friend, you are so kind :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

릴리스

R2019b

태그

질문:

2019년 10월 29일

댓글:

2019년 11월 1일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by