Why the ouput of disp input function become looping?

조회 수: 1(최근 30일)
Tyann Hardyn
Tyann Hardyn 2021년 9월 7일
댓글: Tyann Hardyn 2021년 9월 7일
Hi, Matlab Community.
I wanna ask, about the output of my code below :
%a) Find The Least Square Lines (Polynomial) That Best Fits On The Data On The Table
x = [2:2:12]; %Declare x matrix
y = [3.9572, 4.4854, 5.8003, 6.1419, 7.4218, 8.9157]; %Declare y matrix
masukkan = double(input('Input predictor functions orde :'));
orde = string(masukkan);
coefficient = polyfit(x, y, masukkan);
xc = [2:0.0001:12]; %Mendeklarasi Variabel xc sebagai input fungsi polyfit orde 1
yfit = polyval(coefficient, xc);
disp(sprintf("Dengan menggunakan Polyfit Orde ke %s, nilai y nya adalah %.3f", char(orde), yfit)); %<This code's output
%are always looping (why??)
curve = figure( 'Name', 'Penentuan Best Fit Least-Square Line dari Data X dan Y dengan Polyfit Orde 1' );
curve.WindowState='maximized';
plot(xc, yfit, 'Color', 'w', 'LineWidth',1.1);
hold on
plot(x, y, 'mo', 'MarkerFaceColor',[0.6 0.6 1], 'MarkerSize',5.5);
hold off
set(gca,'color',[0.4 0.4 0.4]);
title(sprintf('Best-Fit Least Square Line menggunakan Fungsi Polyfit (Polinomial Orde ke %s)', orde), 'fontweight','bold','fontsize',15.5);
xlabel('Data x','fontweight','bold','fontsize',14);
ylabel('Data y', 'fontweight','bold','fontsize',14);
legend(sprintf('Best Fit Least Square Polynomial Line (Orde ke %s)', orde), 'Data x vs y pada soal', 'Location', 'NorthWest', 'Interpreter', 'none', 'Parent', curve, 'color', 'c', 'fontsize',12);
grid on;
The plotting part is good, but the output of disp function of input function (masukkan variable) is looping to infinite until it is said :
Output truncated. Text exceeds maximum line length for Command Window display.
The input function is only declare 1 variable (our keyboard number0 but why the result is such a looping of sprintf?
Thank you everyone /.\ /.\ /.\

채택된 답변

per isakson
per isakson 2021년 9월 7일
편집: per isakson 2021년 9월 7일
The expected output is repeated a zillion times, because yfit is a vector with a zillion elements
>> whos yfit
Name Size Bytes Class Attributes
yfit 1x100001 800008 double
  댓글 수: 1
Tyann Hardyn
Tyann Hardyn 2021년 9월 7일
alright, thanks. Thats my mistake..

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by