You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Interp2 and contourf -- CAN ANYONE HELP ME ?
4 views (last 30 days)
Show older comments
I have data set. I will use interp2 and contourf command.How do I get using (2-D) two dimension interpolation in "contourf" command. Can anyone help me ? (39 elements)
x = [-10 -9.5 -9 -8.5 -8 -7.5 -7 -6.5 -6 -5.5 -5 -4.5 -4 -3.5 -3 ....
-2.5 -2 -1.5 -0.5 0 0.5 1 1.5 2 2.5 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10];
y = [0.98391 0.99116 0.99551 1.00565 0.99406 0.97377 0.99406 0.98391 0.98681 0.96797....
0.95348 0.92884 0.89986 0.90565 0.93174 0.96652 1.02304 1.08681 1.14188 1.13029....
1.10420 1.09986 1.09261 1.07087 1.06942 1.05928 1.06507 1.06797 1.05203 1.05493....
1.05348 1.07522 1.06217 1.07667 1.05203 1.05058 1.05638 1.06797 1.04333];
6 Comments
Walter Roberson
on 23 Feb 2014
Do you have a Z(J,K) value corresponding to each X(J), Y(K) ?
Or do you just have a Z vector such that X(J), Y(J), Z(J) go together ("scattered" values) ?
What locations do you want to interpolate at?
Are you trying to take the contour plot of a scattered set of data?
Erhan Ferdi
on 23 Feb 2014
Edited: Erhan Ferdi
on 23 Feb 2014
I will go together scattered values. How do I set Z(x,y)? Can u help me :) , I want to like this pictures:
Walter Roberson
on 23 Feb 2014
I'm sure my friend would have been thrilled to have me leave her birthday celebration to assist you.
Erhan Ferdi
on 23 Feb 2014
No problem :) I waited for you.
Image Analyst
on 24 Feb 2014
We don't know how old your MATLAB is, so tell us do you have griddedInterpolant()? If not, then do you have TriScatteredInterp()? If not then you should have griddata. Can you apply the examples in any of those functions to your situation?
Erhan Ferdi
on 24 Feb 2014
Edited: Erhan Ferdi
on 24 Feb 2014
I have r2013b version MATLAB. I newbie in MATLAB, and I have commands only griddedInterpolant.(and It has been ScatteredInterp()) I don't know to take V datas(matrix) , so I can not get the appropriate coordinate system.
((Vq = interp2(X,Y,V,Xq,Yq);%I don't take Xq Yq and V(specially this "V")
If you have a chance,can you explain with my data?
Answers (1)
Walter Roberson
on 24 Feb 2014
The x and y data that you show are not sufficient to construct the plot you ask for. You need the additional data matrix that has the values between 299.94 and 300.14. If that data matrix is 2 dimensional then you have a standard contourf() plot. If, though, the data matrix is a vector whose length is the same as x and y, then you would have a scattered plot that would have to be interpolated, and it would be that vector of data that would be "V".
When I examine your x and y values, and compare to your desired plot, it appears to me that you must have a 2D array of temperatures, and so need a standard contourf() plot.
22 Comments
Erhan Ferdi
on 24 Feb 2014
Edited: Erhan Ferdi
on 24 Feb 2014
I want to make 2D Version with scattered interpolation values.
clear;
clc;
x = [-10 -9.5 -9 -8.5 -8 -7.5 -7 -6.5 -6 -5.5 -5 -4.5 -4 -3.5 -3 ....
-2.5 -2 -1.5 -0.5 0 0.5 1 1.5 2 2.5 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10];
y = [0.98391 0.99116 0.99551 1.00565 0.99406 0.97377 0.99406 0.98391 0.98681 0.96797....
0.95348 0.92884 0.89986 0.90565 0.93174 0.96652 1.02304 1.08681 1.14188 1.13029....
1.10420 1.09986 1.09261 1.07087 1.06942 1.05928 1.06507 1.06797 1.05203 1.05493....
1.05348 1.07522 1.06217 1.07667 1.05203 1.05058 1.05638 1.06797 1.04333];
xlin = linspace(min(x),max(x),39);
ylin = linspace(min(y),max(y),39);
[X,Y]=meshgrid(xlin,ylin);
Z=peaks(39);
surfl(X,Y,Z)
grid off
axis on
shading faceted
Walter Roberson
on 24 Feb 2014
Edited: Walter Roberson
on 24 Feb 2014
The above code uses a regular grid rather than a scattered set of coordinates.
An example:
x = [-10 -9.5 -9 -8.5 -8 -7.5 -7 -6.5 -6 -5.5 -5 -4.5 -4 -3.5 -3 ....
-2.5 -2 -1.5 -0.5 0 0.5 1 1.5 2 2.5 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10];
y = [0.98391 0.99116 0.99551 1.00565 0.99406 0.97377 0.99406 0.98391 0.98681 0.96797....
0.95348 0.92884 0.89986 0.90565 0.93174 0.96652 1.02304 1.08681 1.14188 1.13029....
1.10420 1.09986 1.09261 1.07087 1.06942 1.05928 1.06507 1.06797 1.05203 1.05493....
1.05348 1.07522 1.06217 1.07667 1.05203 1.05058 1.05638 1.06797 1.04333];
temperature = 299.94 + (300.14 - 299.94) * rand(1,length(x)); %replace with real temperature data
xlin = linspace(min(x),max(x),39);
ylin = linspace(min(y),max(y),39);
[X, Y] = ndgrid(xlin, ylin);
F = scatteredInterpolant(x, y, temperature);
temperatureGrid = F(X, Y);
contourf(X, Y, temperatureGrid);
Erhan Ferdi
on 24 Feb 2014
My brother thank you but my datas are only x and y. Temperature pictures are only example.I showed it as a 2D example. I dont understand temperature integer :) I want to use x and y datas. Please help me. I am sure u know this topic.
Walter Roberson
on 24 Feb 2014
What you want to do cannot be done with the information you have indicated is available.
In order to do a contour plot, you need to have a "height" for some set of (X,Y) points. You have your x and your y but you have no "height" at all -- no temperature, no v, no z.
You can do something like this:
plot(x,y); grid on; set(gca, 'xtick', [])
and you could do the same sort of level plot but with the level lines only going across areas that are present.
Or perhaps you would like something like,
surf(x, 1:length(x), repmat(y,length(x),1))
Erhan Ferdi
on 24 Feb 2014
I would like to take a two-dimensional image. When I use this code ;
- surfl(x, 1:length(x), repmat(y,length(x),1)) picture:
- 1
#plot(x,y); grid on; set(gca, 'xtick', [])
- 2
Walter Roberson
on 24 Feb 2014
Try with
surfl(x, 1:length(x), repmat(y,length(x),1), 'light')
Erhan Ferdi
on 24 Feb 2014
Edited: Erhan Ferdi
on 24 Feb 2014
It didn't work.
Walter Roberson
on 24 Feb 2014
It works on my system -- or at least it does something graphic-y and 3 dimensional.
Could you sketch how you want the result to look and post the sketch? If you do not have colored ink handy then just write the names of the colors and point to where they should go.
Erhan Ferdi
on 24 Feb 2014
Edited: Erhan Ferdi
on 24 Feb 2014
I want to take 2D image with interp2. I want sketch version. Please specify the colors you. I waiting for you. Thanks :)
Walter Roberson
on 25 Feb 2014
Put in whatever colors you want to appear in the final plot.
In order to use interp1(), you need one fixed coordinate (x) and one coordinate that varies with the first coordinate (y). In order to use interp2(), you need two fixed coordinates (x, y) and one coordinate (z) that varies with x and y.
But all you have is one fixed coordinate (x) and one coordinate (y) that varies with x. You are missing a second fixed coordinate before you can use interp2()
Erhan Ferdi
on 25 Feb 2014
Can i take Z=peaks(n)command? How do I use interp2 help me Mr.Roberson? Can u explain with an example?
Erhan Ferdi
on 25 Feb 2014
Edited: Erhan Ferdi
on 25 Feb 2014
Yes,true i sent you.I guess I could not tell you,Mr.Walter. I want to take with interp2 and contourf commands. My goal is to get these two-dimensional image.
Walter Roberson
on 25 Feb 2014
If you look at the top left plot, notice the red marks. Each of those red marks has an associated x, y, and z value. When you have the coordinate vectors x(J), y(J), z(J) then you can create contour plots in the manner I showed above, http://www.mathworks.co.uk/matlabcentral/answers/118606#comment_198213 just replacing the random setting of "temperature" with your actual z data.
Let me ask about what your overall aim is. Are you trying to create some simulated data to compare griddedInterpolant and RBF interpolating?
Erhan Ferdi
on 25 Feb 2014
Edited: Erhan Ferdi
on 25 Feb 2014
Yes, i want to set contourf command with scattered interpolating.And[Z(J,K)]It correspond to each X(J), Y(K) This pictures only 2D example. I dont need RBF interpolating.
Walter Roberson
on 25 Feb 2014
You do have Z data? You already have one Z(J,K) for each X(J), Y(K) ? Or you have X(J), Y(J), Z(J) ?
Erhan Ferdi
on 25 Feb 2014
Mr.Roberson, I dont have Z data . How can I do create it ?
Walter Roberson
on 25 Feb 2014
Do you want artificial Z data? If so, then what characteristics do you want for the artificial Z data? How many valley, how many peaks, and so on.
Walter Roberson
on 25 Feb 2014
Sorry it is my bedtime now (03:25 here).
Erhan Ferdi
on 25 Feb 2014
Edited: Erhan Ferdi
on 25 Feb 2014
Yes, Mr.Roberson. I want artificial Z data with peaks. I think, let's do 39 peaks. Because, i have 39 values.(Z=peaks(39)=> I know only this command.) But, I think again, you know better.I want to take according to the darkness color.
So, I must create with red>orange>yellow>green colors.
If you can do this (y axis values):
Red ==> The largest value
Orange and Yellow ==> In the middle value
Green ==> In the low value
Finally, x (axis) value only numerical collocations.
Please send me code. I waiting for you. Sleep Well ! :))
Walter Roberson
on 25 Feb 2014
peaks(39) asks for a 39 x 39 matrix, not for 39 peaks.
Erhan Ferdi
on 26 Feb 2014
Help me I dont make it :(
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)