how to plot a contour plot with excel data??
Show older comments
I have to plot a contour plot for excel data. I have two variables x and y , and the individual variables contain 50 data ponts
i defined the data for the variables x and y
contour(x,y) ...i have written code but it is showing the error .can someone tell me where i did mistake ?
5 Comments
VBBV
on 31 Mar 2021
What is the error? Attach your data file if possible
sunitha
on 31 Mar 2021
K = readmatrix('contour gr.xlsx');
F = K(:,1)+ 2*K(:,2); % your example matrix which specifies function in terms of X and Y
Z = repmat(F,1,49); % your example Z matrix
contour(K(:,1),K(:,2),Z) % your contour plot
Try above
sunitha
on 31 Mar 2021
sunitha
on 31 Mar 2021
Answers (2)
from the folder containing your excel file run
the error about Z may be related to the fact that contour is waiting for a missing variable. But a turnaround is to give to the function an array directly (2D in this case).
Please edit the path to your file (remove the square brackets and put your file location).
%% Import the data
[~, ~, raw] = xlsread('[path to your file here]\contour gr.xlsx','Sheet1');
raw = raw(2:end,:);
%% Create output variable
data = reshape([raw{:}],size(raw));
%% Create table
contourgr = table;
%% Allocate imported array to column variable names
contourgr.ksmgcm3 = data(:,1);
contourgr.SmgL = data(:,2);
%% Clear temporary variables
clearvars data raw;
contour(table2array(contourgr));
Star Strider
on 31 Mar 2021
I cannot see how to do a contour plot of two vectors that do not represent gridded data, since that does not make sense.
However one option could be:
D = readmatrix('contour gr.xlsx');
x = D(:,1);
y = D(:,2);
figure
contourf(x*y.')
.
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!