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

조회 수: 1(최근 30일)
AASHNA SUNEJA 2022년 5월 27일
답변: Voss 2022년 5월 28일
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')

댓글을 달려면 로그인하십시오.

### 채택된 답변

Voss 2022년 5월 28일
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])

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by