I want to represent a set of 2-D experimental data (1 x 10matrix) using a colorbar plot.

1 vue (au cours des 30 derniers jours)
I want to represent a set of 2-D experimental data (1 x 10matrix) using a colorbar plot where y reamins constant and the experimental value changes according to the x cordinate. I am attaching a sample plot i want to make. Also i am attaching the code I tried to do this.
x = [20 22 26 34]; % Random data
y = [0 4 6];
C = [0 1 2 3 ; 1 2 3 4 ; 2 3 4 5];
xSplit = diff(x)/2; % Find edge points
ySplit = diff(y)/2;
xEdges = [x(1)-xSplit(1) x(2:end)-xSplit x(end)+xSplit(end)];
yEdges = [y(1)-ySplit(1) y(2:end)-ySplit y(end)+ySplit(end)];
[XGrid, YGrid] = meshgrid(xEdges,yEdges);
YGrid = flipud(YGrid); % To match expected behavior
C = [[C zeros(size(C,1),1)] ; zeros(1,size(C,2)+1)];% Last row/col ignored
pcolor(XGrid,YGrid,C)
hold on % Plot original data points
[X,Y] = meshgrid(x,y);
Y = flipud(Y);
plot(X,Y,'or')

Réponse acceptée

Voss
Voss le 28 Mai 2022
data = [0 10 15 0 10 17 0 17 30 0];
x_spacing = 30;
y = 18;
n = numel(data);
p = patch( ...
'XData',x_spacing*([0;1;1;0]+(0:n-1)), ...
'YData',repmat(y*[0;0;2;2],1,n), ...
'FaceColor','flat', ...
'CData',data, ...
'EdgeColor','none');
colormap('jet')
cb = colorbar();
cb.Title.String = 'Flow rate(%)';
xticks(x_spacing*(1:n)-0.5*x_spacing)
ylim([0 2*y])
yticks(y)
title('Flow map')
xlabel('X(mm)')
ylabel('Y(mm)')
set(gca(), ...
'Layer','top', ...
'Box','on', ...
'FontWeight','bold', ...
'Position',[0.11 0.75 0.8 0.15])

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by