How to plot pcolor in matlab
Mostrar comentarios más antiguos
Hello everyone,
i want to plot pcolor plot in matlab but i tried i cannot do it. I add my data here and code also
x = [13-04-2021 00:00 13-04-2021 01:00 13-04-2021 02:00 13-04-2021 03:00 13-04-2021 04:00] like this till 14-04-2021 23:00:00
y = [10.23 11.16 12.19 13.31 14.54 15.88 17.35 18.96 20.72 22.66 24.77 27.1 29.65 32.45 35.53 38.92 42.65 46.77 51.32]
z = [2.27E+03 3.94E+03 4.48E+03 6.26E+03 3.18E+03 3.78E+03 5.37E+03 5.60E+03 6.35E+03 8.47E+03 1.05E+04 1.05E+04
1.36E+04 1.12E+04 8.48E+03 3.96E+03 5.84E+03 4.55E+03 3.65E+03 6.17E+03 7.48E+03 6.98E+03 9.84E+03 1.11E+04
5.72E+04 6.90E+04 5.64E+04 4.71E+04 1.94E+04 6.37E+03 6.59E+03 6.89E+03 8.81E+03 9.70E+03 8.11E+03 9.59E+03
1.26E+04 1.34E+04 1.69E+04 1.99E+04 2.18E+04 2.62E+04 2.98E+04 9.09E+03 5.16E+03 8.73E+03 3.96E+03 4.95E+03
5.16E+03 4.06E+03 4.24E+03 6.17E+03 7.99E+03 8.20E+03 6.68E+03 1.07E+04 1.24E+04 1.36E+04 1.78E+04 1.89E+04]
my x data is in one range and y is in another range and my z data is in different size range.
how to plot that graph?
i hope i will get the answer for this thank you in advance.
[x,y] = meshgrid(x,y);
Pcolor(x,y,z);
5 comentarios
Rik
el 9 de Dic. de 2021
You need to find a way to match up your data. It is not clear to me how you are planning to do that. How are you making sure you have as many z values as you have x-y-combinations?
xd = {'13-04-2021 00:00' '14-04-2021 23:00'};
xdt = datetime(xd, 'InputFormat', 'dd-MM-yyyy HH:mm');
x = xdt(1) : hours(1) : xdt(2);
y = [10.23 11.16 12.19 13.31 14.54 15.88 17.35 18.96 20.72 22.66 24.77 27.1 29.65 32.45 35.53 38.92 42.65 46.77 51.32];
z = [2.27E+03 3.94E+03 4.48E+03 6.26E+03 3.18E+03 3.78E+03 5.37E+03 5.60E+03 6.35E+03 8.47E+03 1.05E+04 1.05E+04
1.36E+04 1.12E+04 8.48E+03 3.96E+03 5.84E+03 4.55E+03 3.65E+03 6.17E+03 7.48E+03 6.98E+03 9.84E+03 1.11E+04
5.72E+04 6.90E+04 5.64E+04 4.71E+04 1.94E+04 6.37E+03 6.59E+03 6.89E+03 8.81E+03 9.70E+03 8.11E+03 9.59E+03
1.26E+04 1.34E+04 1.69E+04 1.99E+04 2.18E+04 2.62E+04 2.98E+04 9.09E+03 5.16E+03 8.73E+03 3.96E+03 4.95E+03
5.16E+03 4.06E+03 4.24E+03 6.17E+03 7.99E+03 8.20E+03 6.68E+03 1.07E+04 1.24E+04 1.36E+04 1.78E+04 1.89E+04];
size(x)
size(y)
size(z)
Your data is all different sizes; we cannot test with it, and we cannot figure out what you are trying to do.
vignesh mohan
el 9 de Dic. de 2021
vignesh mohan
el 9 de Dic. de 2021
vignesh mohan
el 9 de Dic. de 2021
Respuestas (1)
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/828415/Book1.xlsx';
T = readcell(filename);
x = [T{2:end,1}];
y = cell2mat(T(1,2:end));
z = cell2mat(T(2:end,2:end));
surf(x, y, z.', 'edgecolor', 'none');
34 comentarios
vignesh mohan
el 9 de Dic. de 2021
Image Analyst
el 9 de Dic. de 2021
Then use xlsread() instead.
vignesh mohan
el 9 de Dic. de 2021
Book1 = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/828415/Book1.xlsx';
%this line is only required if you're downloading the file, instead of
%using a local copy
Book1=websave('Book1.xlsx',Book1);
T = xlsread(Book1)
vignesh mohan
el 9 de Dic. de 2021
vignesh mohan
el 9 de Dic. de 2021
Image Analyst
el 9 de Dic. de 2021
Book1 needs to be a string, and apparently it's not. Try
fullFileName = fullfile(pwd, 'Book1.xlsx');
if isfile(fullFileName)
[numbers, strings, T] = xlsread(fullFileName);
else
warningMessage = sprintf('File not found:\n%s', fullFileName);
uiwait(errordlg(warningMessage));
return;
end
T will be the raw cell array while numbers is just the numbers (with nan wherever there is a string in the matrix), and strings is a cell array with just the text cells.
vignesh mohan
el 9 de Dic. de 2021
Image Analyst
el 9 de Dic. de 2021
You must have a really old version. Use exist() instead:
if exist(fullFileName, 'file')
vignesh mohan
el 10 de Dic. de 2021
vignesh mohan
el 10 de Dic. de 2021
Walter Roberson
el 10 de Dic. de 2021
surf(x, y, z.');
vignesh mohan
el 10 de Dic. de 2021
Walter Roberson
el 10 de Dic. de 2021
please post your current code
vignesh mohan
el 10 de Dic. de 2021
Editada: Walter Roberson
el 11 de Dic. de 2021
Walter Roberson
el 11 de Dic. de 2021
The code works when I try it in R2016a on my system.
To debug this, give the commands
dbstop in matlab.graphics.chart.internal.ctorHelper
surf(x, y, z.')
The code should run, but stop in ctorHelper.m . When it stops, please show us the value of the variable named pvpairs -- and also please show us class(obj)
vignesh mohan
el 13 de Dic. de 2021
vignesh mohan
el 13 de Dic. de 2021
Editada: Walter Roberson
el 13 de Dic. de 2021
Walter Roberson
el 13 de Dic. de 2021
Please show the output for
which -all surf
Your pvpairs are not even in the same order that I would expect for your release. I would expect
'XData' [1x84 double] 'YData' [1x19 double] 'ZData' [19x84 double] 'Parent' [1x1 Axes]
vignesh mohan
el 13 de Dic. de 2021
Andebo Waza
el 17 de Dic. de 2024
Editada: Walter Roberson
el 17 de Dic. de 2024
Dear all,
I need your help. I have wind data in 2D (Height, Time). I want to plot a 60-minute average data, and I want to do that using pcolor plot. I managed to generate the plot with the original data (30 min), but failed to do it on a 60-min average. I am relatively new to netcdf data. Any help is greatly appreciated!
Here is my code for original data:
clear all
close all
clc
ncid = netcdf.open('wl_geomar_CSM_l2_v04_20240916.nc','NC_NOWRITE');
filename = ncinfo('wl_geomar_CSM_l2_v04_20240916.nc');
disp(filename);
ncdisp('wl_geomar_CSM_l2_v04_20240916.nc');
longitude = ncread('wl_geomar_CSM_l2_v04_20240916.nc','lon');
latitude = ncread('wl_geomar_CSM_l2_v04_20240916.nc','lat');
time = ncread('wl_geomar_CSM_l2_v04_20240916.nc','time');
epoch = datetime(1970, 01, 01)
T = epoch + seconds(time)
u = ncread('wl_geomar_CSM_l2_v04_20240916.nc','u');
v = ncread('wl_geomar_CSM_l2_v04_20240916.nc','v');
wspeed = ncread('wl_geomar_CSM_l2_v04_20240916.nc','wspeed');
height = ncread('wl_geomar_CSM_l2_v04_20240916.nc','height');
u_mean=sqrt(u.^2+v.^2+wspeed.^2);
mymap=pcolor(T,height,u_mean);
shading interp
h= colorbar
caxis([0 20])
drawnow
ylabel(h,'Mean wind speed (m/s)');
grid on
xlabel('Time (UTC)')
ylabel('Height (m)')
xtk=xticks;
I would be happy to provide you the data if needed.
Steven Lord
el 17 de Dic. de 2024
What does "failed to do it on a 60-min average" mean in this context?
- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
Walter Roberson
el 17 de Dic. de 2024
TT = timetable(T, u, v, wspeed, height);
TT60 = retime(TT, minutes(60));
u_mean60 = sqrt(TT60.u.^2 + TT60.v.^2);
mymap60 = pcolor(TT60.T, TT60.height, TT60.u_mean60);
Andebo Waza
el 18 de Dic. de 2024
Thank you so much. Here is the error message I am getting after I tried to plot it using your code:
" Error using timetable (line 328)
All table variables must have the same number of rows."
Walter Roberson
el 18 de Dic. de 2024
Please show the output for
whos T u v wspeed height
Sebastian
el 18 de Dic. de 2024
Here is the output:
>> whos T u v wspeed height
Name Size Bytes Class Attributes
T 48x1 384 datetime
height 99x1 792 double
u 99x48 38016 double
v 99x48 38016 double
wspeed 99x48 38016 double
Andebo Waza
el 18 de Dic. de 2024
@Walter Roberson, I can also share the data with you. Just let me know if you need it.
Walter Roberson
el 19 de Dic. de 2024
u = u.';
v = v.';
wspeed = wspeed.';
TT = timetable(T, u, v, wspeed);
TT60 = retime(TT, minutes(60));
u_mean60 = sqrt(TT60.u.^2 + TT60.v.^2);
mymap60 = pcolor(TT60.T, height, TT60.u_mean60);
Andebo Waza
el 28 de Dic. de 2024
Dear @Walter Roberson
I am still getting an error message, "Error using timetable/retime (line 142)
All input timetables must have row times with the same data type as target time
vector."
Walter Roberson
el 28 de Dic. de 2024
Is that error message coming from the retime() call?
If so, try
TT60 = retime(TT, 'regular', 'linear', 'timestep', minutes(60));
Andebo Waza
el 29 de Dic. de 2024
Here is the final one:
u = u.';
v = v.';
wspeed = wspeed.';
TT = timetable(T, u, v, wspeed);
TT60 = retime(TT, 'regular', 'linear', 'timestep', minutes(60));
%TT60 = retime(TT, minutes(60));
u_mean60 = sqrt(TT60.u.^2 + TT60.v.^2+TT60.wspeed.^2);
mymap60 = pcolor(TT60.T, height, u_mean60').
Andebo Waza
el 30 de Dic. de 2024
Thank you again for helping me. I am now trying to write another code for the same dataset (this time I have the python code but I need to trasnlate that into Matlab code as I do not use Python). Could you please help me with is part too? I really apperciate your help.
Here is the python that I need to re-write in Matlab.
#filter signals for plotting, which are only marginally above molecular signal
bsc_mask = bsc_par_prl < np.repeat(np.reshape(1.5*mol_bsc, (1,len(mol_bsc))), att_bsc_crs_avg.shape[0], axis=0)
depol_par_masked = np.ma.array(depol, mask=bsc_mask)
bsc_par_masked = np.ma.array(bsc_par_prl, mask=bsc_mask)
Walter Roberson
el 30 de Dic. de 2024
Sorry, I do not know how to read python. In particular I do not know the meaning of np.ma.array especially in conjugation with the mask= parameter.
Andebo Waza
el 31 de Dic. de 2024
@Walter Roberson, No worries. I managed to write the code.
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


