Effacer les filtres
Effacer les filtres

Why the ouput of disp input function become looping?

1 vue (au cours des 30 derniers jours)
Tyann Hardyn
Tyann Hardyn le 7 Sep 2021
Commenté : Tyann Hardyn le 7 Sep 2021
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' );
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 /.\ /.\ /.\

Réponse acceptée

per isakson
per isakson le 7 Sep 2021
Modifié(e) : per isakson le 7 Sep 2021
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

Plus de réponses (0)


En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by