Why is surf giving an incorrect plot?

5 Ansichten (letzte 30 Tage)
Sagar Limaye
Sagar Limaye am 28 Okt. 2016
Beantwortet: Walter Roberson am 24 Jan. 2017
Here's what I did. I computed the correlation of two images and created a surface plot. Then, in the location of the peak in that plot, I set the value in the correlation matrix to 0 to get rid of that peak. When I tried to plot the surface again, the peak wasn't gone.
figure; surf(correlation); %correlation is the matrix of correlation coefficients at all points of one of the images
[ypeak, xpeak] = find(correlation == max(correlation(:));
correlation(xpeak, ypeak) = 0;
figure; surf(correlation);
In the last plot, there is still a peak of 100 (no change from the first plot) at (xpeak, ypeak)
What's also weird is that if I view the ZData of the last surface plot, the value at (xpeak, ypeak) is 0.

Antworten (2)

mustafa ozendi
mustafa ozendi am 24 Jan. 2017
Hello Sagar, I coded as you show and it works. My codes are below. It finds the max and replaces it with zero. When I plotted it works.
clc
clear all
cor_mat = rand(50,50); %generate a random matrix
perm_cor_mat = cor_mat; %assign cor_mat to a lets say permanent matrix
perm_cor_mat(25,25) = 100; %assign a max value
figure; surf(perm_cor_mat); %plot the correlation with peak
[ypeak, xpeak] = find(perm_cor_mat == max(perm_cor_mat(:))); %find peak
perm_cor_mat(xpeak, ypeak) = 0; %replace the peak with 0
figure; surf(perm_cor_mat); %plot the correlation matrix again

Walter Roberson
Walter Roberson am 24 Jan. 2017
surf() and pcolor() use the same graphics object. And that implies that surf() outputs one row and column fewer than the original data, the same way that pcolor does. The input data is treated as the vertices and what is drawn as having color are the faces interpolated between the vertices. So when you set a point to 0 you get a depression there but the faces are going to be mostly nonzero.
Also remember that the more than one point might match the maximum. If it does then xpeaks and ypeaks would be a vector, and when you use a vector as an index for individual array positions, you are addressing all the combinations of values from the vectors. That is going to end up setting too many points to 0. The code should use linear indexing instead,
Idx = find(....)
Array(Idx) = 0;

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by