# how to get matlab to disply zero as the last value

1 ビュー (過去 30 日間)
Opariuc Andrei 2021 年 4 月 16 日

% all functioning and all, i'm supposed to get 19 values for x,y,PmJ,KpJ but matlab is diaplaying only 18 values ,
% the 19 th values for each the mentioned are 0 how can i get matlab to
% display the last 4 values of 0 ? i need those in the 2 plots below , if i
% manually add the last values of 0 for x,y,PmJ,KpJ the plots are a bit
% different which is what i need
g=9.81;
Pm=996.76;
E=0.995;
h0=0.003;
RhoA=1.216;
U=40.88;
a=[0;2;10;19;34;56;78;102;130;150;124;102;75;56;33.5;19;9.5;15;] ;
b=[0;-4.39;-9.01;-11.42;-13.19;-13.25;-11.61;-8.67;-4.17;0;5.22;8.67;11.91;13.25;13.16;11.42;8.82;3.83;] ;
h=[0.003;0.099;0.03;0.008;-0.011;-0.013;-0.0105;-0.0046;0.0045;0.026;-0.0021;-0.025;-0.05;-0.075;-0.12;-0.13;-0.17;-0.073;];
x=a/150
y=b/150
PmJ=round(Pm*g*(h-h0))
KpJ=(PmJ/((RhoA*U^2)/2))
figure
plot(x,KpJ);grid on;axis tight ;
figure
plot(x,y);grid on;axis tight;axis equal;

サインインしてコメントする。

### 採用された回答

Clayton Gotberg 2021 年 4 月 16 日
a,b, and h are 18x1 so you'll only get 18x1 unless you add a zero at the end.
You can do that in a few ways:
x(19)=0;
%or
x(end+1)=0; %especially useful if you don't know the length of the matrix you are adding to
%or
x = [x; 0];

サインインしてコメントする。

### カテゴリ

Find more on Desktop in Help Center and File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by