how to create contour
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Muhsin ACAR
il 18 Gen 2017
Commentato: Walter Roberson
il 19 Gen 2017
Hello; Can anyone help me create contour map for attached file? Thank you,
Best, Muhsin A
0 Commenti
Risposta accettata
Walter Roberson
il 19 Gen 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 Commenti
Walter Roberson
il 19 Gen 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);
Più risposte (1)
Chad Greene
il 19 Gen 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 Commenti
Vedere anche
Categorie
Scopri di più su Contour Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!