How to limit the output decimal places?

43 views (last 30 days)
Andi
Andi on 8 Apr 2022
Commented: Walter Roberson on 10 Apr 2022
Hi everyone,
I required upto 10 decimal place answer for my output, but after few decimal place its shows zero. Earlier i attempted with longEng command but still the issue is same. May someone help put me here.
my script is as follows
clear all
clc
raw=readmatrix('Hourly_ev_05_04_2022');
data_a=raw';
data_a1=data_a(1:24,:);
rate=(mean(data_a1))';
data_a2=data_a(25:96,:);
ev_hr=data_a2;
bbb=rate;
position = 0; % position of plot in subplot
fig_num = 1; % figure() number
for S=184:184
uu=S;
r=bbb(uu); % for first event
data=ev_hr(:,uu);
u=transpose(data);
for n=1:length(u);
dt=n;
for i=1:length(u)-(n-1);
K=u(i:i+n-1);
k=sum(K);
b(i,n)=(k-(r)*(dt))/sqrt(r*dt);
end
end
T=transpose(b);
%format long
for ii=1:72
for jj=1:72-(ii-1)
if(ii==1)
b1(ii,jj)=T(ii,jj);
else
b1(ii,jj+(ii-1))=T(ii,jj);
end
end
end
ddd=max(b1);
vvv=max(ddd);
for ii=1:length(b)
for jj=1:72
if(b1(ii,jj)==0)
b1(ii,jj)=nan;
end
end
end
yyy=max(b1);
pp=max(yyy);
beta_new=pp';
c = NaN(72,24);
c2=[c b1];
x = [-23:72]' ;
y = [1:72]' ;
figure;
ax1=subplot(2,1,1);
pcolor(x,y,c2);
shading interp ;
cb = colorbar('Location','west')
cb.Label.String = '\beta';
cb.Label.Rotation = 360;
set(cb.Label,'FontSize',11);
ylh=ylabel('Time interval (hr)', 'FontSize', 9);
xline(0,'--r', 'LineWidth', 1.5);
xline(-0.4,'-k', 'LineWidth', 1.5);
set(gca,'XTickLabel',[]);
ax1_pos = get(ax1,'Position');
yl=ylim;
ax = gca;
ax.FontSize = 8;
grid on
patch([46 53 53 46], [yl(1) yl(1) yl(2) yl(2)], [0.01 0.01 0.01], 'FaceAlpha', 0.2 )
%patch([27 35 35 27], [yl(1) yl(1) yl(2) yl(2)], [0.01 0.01 0.01], 'FaceAlpha', 0.2 )
ylh.Position(1) = ylh.Position(1) - 0.2;
text(50,yl(2)-5,sprintf('\\beta_{max} = %.1f',beta_new), ...
'VerticalAlignment','top');
% text(30,yl(2)-20,sprintf('\\beta_{max} = %.1f',16.1), ...
% 'VerticalAlignment','top');
%middleCentered
ax2=subplot(2,1,2);
set(ax2, 'Position', [.13 .3 .775 .25]);
A=data_a(:,uu);
ss= sum(A)+20;
b=cumsum(A);
h=[-23:72];
plot(h,b, 'b', 'LineWidth', 1.5)
ylabel('Cummulative events', 'FontSize', 9)
xlabel('Time (hr)', 'FontSize', 9)
xline(0,'--r', 'LineWidth', 1.5);
xline(-0.4,'-k', 'LineWidth', 1.5);
axis([-23 72 0 ss])
yl=ylim;
% text(25,yl(2),sprintf('\\beta_{max} = %.1f',beta_new), ...
% 'VerticalAlignment','top');
grid on
patch([46 53 53 46], [yl(1) yl(1) yl(2) yl(2)], [0.01 0.01 0.01], 'FaceAlpha', 0.2 )
%patch([27 35 35 27], [yl(1) yl(1) yl(2) yl(2)], [0.01 0.01 0.01], 'FaceAlpha', 0.2 )
ax = gca;
ax.FontSize = 8;
%f = gcf;
%exportgraphics(gca,'Ev_01.png','Resolution',300)
end
Here is the output (3 and 5 coloumn and 12th rows showing zero).

Answers (1)

Walter Roberson
Walter Roberson on 8 Apr 2022
The format command does not affect the Variable Browser.
The format for the variable browser can be changed for each variable. While you are browsing the variable, click on the View tab, and there is a drop-down there for Number Display Format.
You can change the default display format for the variable browser using Preferences -> Variables -> Format (Default array format)
  10 Comments
Andi
Andi on 8 Apr 2022
Yes, i see that but regarding my script more or less everthing is same then why i get some values as empty (NaN)
Walter Roberson
Walter Roberson on 10 Apr 2022
When you run the code with the debugging added, on your system, what output is shown by the debugging?
If you have a recent enough MATLAB, then you should be able to copy and run exactly the code I posted, without even modifying it to change the file name. If it works that way but fails when you change the file name to refer to your local system, then that would give us more information about what to look for.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!