Plot 2D contour graph with two variables.
Show older comments
I need to create a 2D contour plot for the data attached in excel sheet. I am also attaching a figure for reference. I want to plot RC1 against RC2 with their respective values.

7 Comments
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1248612/Book1.xlsx') ;
RC1 = T.RC1 ;
RC2 = T.RC2 ;
val = T.Values ;
scatter(RC1,RC2,[],val,'filled')
What you have is a curve.....how you are expecting a plane?
naila zaman
on 1 Jan 2023
Walter Roberson
on 1 Jan 2023
So for row K you would plot at location x = RC1(K), y = RC2(K), z = column2(K), and column4(K) should be plotted in the 4th dimension??
naila zaman
on 1 Jan 2023
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1248612/Book1.xlsx') ;
RC1 = T.RC1 ;
RC2 = T.RC2 ;
col2 = T{:,2};
col4 = T{:,4};
mask = ismissing(RC1) | ismissing(RC2) | ismissing(col2) | ismissing(col4);
RC1(mask) = [];
RC2(mask) = [];
col2(mask) = [];
col4(mask) = [];
F2 = scatteredInterpolant(RC1, RC2, col2);
F4 = scatteredInterpolant(RC1, RC2, col4);
min1 = min(RC1); max1 = max(RC1);
min2 = min(RC2); max2 = max(RC2);
N = 150;
vec1 = linspace(min1, max1, N);
vec2 = linspace(min2, max2, N+1);
[G1, G2] = ndgrid(vec1, vec2);
Z2 = F2(G1, G2);
Z4 = F4(G1, G2);
subplot(3,1,1)
contourf(G1, G2, Z2); colorbar();
title('column 2')
subplot(3,1,2)
contourf(G1, G2, Z4); colorbar();
title('column 4')
subplot(3,1,3)
contourf(G1, G2, sqrt(Z2.^2 + Z4.^2)); colorbar()
title('wild guess - sqrt(sum of squares)')
Well, that wild guess didn't work out!
Or maybe even something as simple as
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1248612/Book1.xlsx') ;
% xdata and x-dependent vector
RC1 = T.RC1;
col2 = T{:,2};
% ydata and y-dependent vector
RC2 = T.RC2;
col4 = T{:,4};
% xdata is shorter; trim
mask = ismissing(RC1) | ismissing(col2);
RC1(mask) = [];
col2(mask) = [];
% col2 is invariant on y
% col4 is invariant on x
% combine the two as 2-norm?
z = sqrt((col2.').^2 + col4.^2);
contourf(RC1,RC2,z);
colorbar
???
naila zaman
on 3 Jan 2023
Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

