Hi all, I wanted to define the color axis range based on the number of the ii in this for loop, but I don't know what is wrong, can someone please explain?
for ii = 1:16
ax(ii) = subplot(4,4,ii);
h{ii} = pcolor(LON,LAT,Temp,3,'omitnan')));
set(h{ii}, 'EdgeColor', 'none');
shading interp;
colorbar;
if ii == 1 && 5 && 9 && 13
caxis([0 8]);
elseif ii == 2 && 6 && 10 && 14
caxis([6 12]);
elseif ii == 3 && 7 && 11 && 15
caxis([6 12]);
elseif ii == 4 && 8 && 12 && 16
caxis([12 18]);
end
setup_plots(ax(ii))
end

 채택된 답변

chicken vector
chicken vector 2023년 4월 26일

0 개 추천

By axis color, do you mean something like this?
nPoints = 10;
[X,Y] = meshgrid(-3:6/nPoints:3,-3:6/nPoints:3);
Z = peaks(X,Y);
cmap = jet;
figure;
tiledlayout(4,4)
for j = 1 : 16
nexttile;
pcolor(Z)
idx = (1:16) + (j-1)*16;
colormap(gca,cmap(idx,:));
end
Result:

댓글 수: 4

Ashfaq Ahmed
Ashfaq Ahmed 2023년 4월 26일
No, I meant to set up different ranges for the colorbar based on the nnumber of ii
Ashfaq Ahmed
Ashfaq Ahmed 2023년 4월 26일
For example, when ii is 1 or 5 or 9 or 13, the range of the colorbar axis should be between 0 to 8. When ii = 2 or 6 or 10 or 14, the range should be between 6 to 12 and so on.
chicken vector
chicken vector 2023년 4월 26일
편집: chicken vector 2023년 4월 26일
The are two errors in your conditions:
1)The && operator means ‘and’ but here you need ‘or’
2) You also need to repeat the portion ‘ii ==‘
So, for example, first condition should be:
if ii == 1 || ii == 5 || ii == 9 || ii == 13
Or, alternatively, you can use:
if rem(ii,4) == 1
…
elseif rem(ii,4) == 2
…
elseif rem(ii,4) == 3
…
else
…
end
Sorry for bad formatting, but I’m typing from my phone.
Ashfaq Ahmed
Ashfaq Ahmed 2023년 4월 26일
Perfect! Thank you so much!

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Color and Styling에 대해 자세히 알아보기

질문:

2023년 4월 26일

댓글:

2023년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by