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

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

 采纳的回答

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.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

产品

版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by