Plotting a contour plot with excel data

Hello everyone,
I want to plot a contour plot with the attached excel data. So the colour bar on the right needs to be the RH. The x axis is basially the first column L which is relative to R1......R13. For exaomple 1*R, 2*R. The different initial R should be on the y-axis. How do I best do this?
Thanks in advance

 Accepted Answer

doc readmatrix
Import your data into a 2D array and then decide what columns you want to plot using contourf

12 Comments

I tried it but it didn't work.
Could you paste your code? What is the error you are getting?
contourf(L1,R14,RH1)
k = colorbar;
k.Label.String = 'Relative Humidity (%)';
xlabel('Length (R)')
ylabel('Radius (\mum')
%L1 is the A-column (I removed the R from the xlsx file so the first column just goes from 1-20)
%R14 is the Q-column
%RH1 is the O-colume with the relative humidity
the error I'm getting is that z must atleast be a 2x2 matrix
Look at the sizes of L1, R14 and RH1. In order to draw a contourf you need some gridded data or at the least some data with 2-dimensions.
asd ad
asd ad on 12 Aug 2020
Edited: asd ad on 12 Aug 2020
All of them are 21x1 matrix. How do I fix this problem? Because I have three sets of data and I need RH on the colour bar, the length from 1-20 on the x-axis and the y-axis the R.
Okay, then first you would have to convert them to grid data. (Assuming RH1 is the result at [x,y] points created by L1 and R14)
[L1_xy,R14_xy]=meshgrid(L1,R14); % <- Size of L1_xy, R14_xy would be 21x21
RH1_xy = diag(RH1); % <- size of RH1_xy would be 21x21
contourf(L1_xy,R14_xy,RH1_xy);
The thing is RH1 is independent of R14 and L1. L1 is dependent on R14 for example L1 is from 1 to 20 and each point at L1 is dependent on the intial R14. For example 20*R14 for the first reading gives 5 as the R14 is 0.25. Similarly for every reading it is like that. This is the graph I'm getting now.
Is it possible to get an output like this?
P.S. This is another graph I did with my initial plot code
What is you x- and y-axis? What is the variable which depends on x and y values?
In the second plot you have here, the colormap variable Evaporation Time (s) is available at various Relative Humidity (%) and Volume (mm3) combinations. As a result, it is possible to obtain such plot.
Similarly, if you have RH values defined at various Distance and Droplet Radius combinations, then you could draw a contour map. If RH is completely independent and you want to use it color, see scatter(). Using scatter plot you can draw points at [L1, R14] values and have them colored according to the respective RH values.
Relative Humidity is dependant on the x and y values because the relative humidity is different for each different R but same for the corresponding L. For example for all L which is 1R, RH will be the same. Similarly all values of R at L =2R the relative humidity will be the same
Ah, now I understood your data.
Try this:
data = xlsread('Book2.xlsx');
R = data(1:14,16); % <- Got your R
% Initialize matrices
L = zeros(21,14);
R1 = zeros(21,14);
RH = zeros(21,14);
for i = 1:size(L,1)
L(i,:) = (i-1)*R;
R1(i,:) = R;
RH(i,:) = data(i,14);
end
contourf(L,R1,RH);
c=colorbar;
xlabel('L');ylabel('R');ylabel(c,'RH');
Thank you for your help :)

Sign in to comment.

More Answers (0)

Categories

Asked:

on 12 Aug 2020

Commented:

on 13 Aug 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!