Why sprint doesn't show a zero value from an array?

조회 수: 2 (최근 30일)
Ranu Ghafour
Ranu Ghafour 2022년 9월 29일
댓글: Ranu Ghafour 2022년 9월 29일
I have the following code, and when I run everthing works perfectly except in the third column of the figure, the title of the histrogram should show zero instead of -14.
u_0=randi(4000,4000);
p=[0 3 7 30 33 36 56 60 64];
c=[-14 -12 -8;-8 -6 -4;0 0 0];
z=[60 40 20;60 40 20;60 40 20];
fig1=figure('Name','Fig 1');
fig1.WindowState = 'Maximized';
a=[1:450:2251];
for s=1:1:9
subplot(3,3,s)
for r=a(:)+p(s)
f1=u_0(:,r);
f1(f1==0)=NaN;
if s==1 || s==4 || s==7
edge=(0:1:25);
elseif s==2 || s==5 || s==8
edge=(0:4:90);
else s=3 | s==6 | s==9;
edge=(0:10:250);
end
hold on
h1=histogram(f1(:,1),"NumBins",20,'Normalization','pdf',"BinEdges",edge);
h2=histogram(f1(:,4),"NumBins",20,'Normalization','pdf',"BinEdges",edge);
h3=histogram(f1(:,6),"NumBins",20,'Normalization','pdf',"BinEdges",edge);
hold off
title(sprintf('D, (25^{o}C,%d,%d)',c(s),z(s)));
end
end

채택된 답변

Jan
Jan 2022년 9월 29일
편집: Jan 2022년 9월 29일
Reduce the clutter:
a=[1:450:2251];
% Easier:
a = 1:450:2251;
[] is Matlab operator for a concatenation. [1:450:2251] concates the vector 1:450:2251 with nothing.
for r=a(:)+p(s)
a(:) is a column vector. Remember, that Matlab's for processes arrays columnwise. So r is set to a(:)+p(s) once and the loop does not run over the elements. Maybe you mean:
for r = a(:).' + p(s)
This is a real loop. Maybe you want this instead:
r = a(:) + p(s); % Without FOR
Whjat is the purpose of:
else s==7 | s==8 | s==9;
? It compares s with 7, 8 and 9, but does not produce an output. The else does not use a condition. So the "s==7 | s==8 | s==9" is dead code only without any effect.
  댓글 수: 1
Ranu Ghafour
Ranu Ghafour 2022년 9월 29일
Changing
else s==7 | s==8 | s==9;
to
else
solved my probelm. Thanks for your support.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by