how to create contour
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Muhsin ACAR
le 18 Jan 2017
Commenté : Walter Roberson
le 19 Jan 2017
Hello; Can anyone help me create contour map for attached file? Thank you,
Best, Muhsin A
0 commentaires
Réponse acceptée
Walter Roberson
le 19 Jan 2017
"the data belongs to only three different randomly selected rows of the color cross section"
That was the missing bit of information. The values that you have been calling "Y" are really the result of measurements along lines, with the measurements not equally spaced, and one of the coordinates of the line given only implicitly, constants for any given "X" "Y" pair.
In the below code, I make the constant information into the x values, and assume the first pair is at x = 1, the second at x = 2, the third at x = 3. I then created scattered interpolants and sample them along a grid and contour the result.
num = csvread('contour.csv', 2);
N = ones(size(num,1),1);
D = [N, num(:,1), num(:,2); 2*N, num(:,4), num(:,5); 3*N, num(:,7), num(:,8)];
F = TriScatteredInterp(D(:,1),D(:,2),D(:,3));
[X,Y] = ndgrid(linspace(0,5,20),linspace(min(D(:,2)),max(D(:,2)),20));
Z = F(X,Y);
contour(X,Y,Z);
2 commentaires
Walter Roberson
le 19 Jan 2017
Yes. You need to adjust how D is built.
For example:
x0 = 11.82; %initial constant position
dx = 3.71; %change in constant position per plot
%the data has internal blank columns that we can write into
%but we need to add one at the end for the final plot
D = [num, zeros(size(num,1),1)];
%calculate the constant values associated with each plot
ngroup = size(D,2)/3;
xvals = repmat(x0 + dx * (0:ngroup-1), size(num,1), 1);
%write the constant values into the data array after the
%associated data group
D(:,3:3:end) = xvals;
%now move every third column to before the other two
neworder = reshape(circshift(reshape(1:size(D,2),3,[]),[-1, 0]),1,[]);
D = D(:,neworder);
%now bring down all of the groups to be 3 wide
D = reshape(D, size(D,1), 3, []), [], 3);
%build an interpolant
F = TriScatteredInterp(D(:,1),D(:,2),D(:,3));
%interpolate at regular intervals
[X,Y] = ndgrid(linspace(0,5,20),linspace(min(D(:,2)),max(D(:,2)),20));
Z = F(X,Y);
%build the contour plot
contour(X,Y,Z);
Plus de réponses (1)
Chad Greene
le 19 Jan 2017
Are you sure you mean you contour? The contour.csv file only contains x and y data--if you want to plot that x and y data as three separate lines you can do so like this:
D = importdata('contour.csv');
x1 = D.data(:,1);
y1 = D.data(:,2);
x2 = D.data(:,4);
y2 = D.data(:,5);
x3 = D.data(:,7);
y3 = D.data(:,8);
plot(x1,y1,'red')
hold on
plot(x2,y2,'blue')
plot(x3,y3,'green')
What's missing from the contour.csv file is any Z data. Columns 3, 6, and 9 are empty.
3 commentaires
Voir également
Catégories
En savoir plus sur Contour Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!