how do i print only the last answer in a for loop

3 ビュー (過去 30 日間)
Zheng Xuan Lim
Zheng Xuan Lim 2020 年 11 月 14 日
コメント済み: VBBV 2023 年 6 月 27 日
function c = newton_interpolation(x,y)
[p,n]=size(x);
c = zeros(n, n);
c(:, 1)= y';
for j=2:n
for k=1:(n-j+1)
c(k,j) = (c(k+1, j-1) - c(k,j-1))/(x(k+j-1)-x(k))
end
end
when i print this i get every itteration of the answer but i only need the last
  1 件のコメント
VBBV
VBBV 2023 年 6 月 27 日
function c = newton_interpolation(x,y)
[p,n]=size(x);
c = zeros(n, n);
c(:, 1)= y';
for j=2:n
for k=1:(n-j+1)
c(k,j) = (c(k+1, j-1) - c(k,j-1))/(x(k+j-1)-x(k)); % put a semicolon here
end
end
c(end,end) %// use the end index for matrix
end
use end index for the c matrix

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

回答 (1 件)

madhan ravi
madhan ravi 2020 年 11 月 14 日
c(k,j) = (c(k+1, j-1) - c(k,j-1))/(x(k+j-1)-x(k)); %<- semicolon

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by