Polyfit matrix from import TXT file
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I am trying to import a TXT file containing 100 rows x 2 columns of data. I then want to take that data and polyfit it. However, what I have been trying so far receives the errror: Warning: Polynomial is not unique; degree >= number of data points. All of my matrices come out with correct data.
My current code:
% Import data
filename = 'A2Q2_input_a.txt';
delimiterIn = ' ';
headerlinesIn = 1;
A = importdata(filename);
for k = [1:100]
D = (A.data(k, :));
domain(k) = D(1));
percent_err(k) = D(2);
% perform linear polyfit function
p_linear_R4 = polyfit(domain,percent_err,1);
3 Commenti
Rik
il 7 Set 2022
Then the answer posted by KSSV should be what you need. If not, attach the file to your question and explain why it doesn't work.
Risposte (1)
KSSV
il 6 Set 2022
% Import data
filename = 'A2Q2_input_a.txt';
T = readtable(filename);
x = T.(1) ;
y = T.(2) ;
% perform linear polyfit function
p_linear_R4 = polyfit(x,y,1);
yi = polyval(p_linear_R4,x) ;
figure
hold on
plot(x,y,'.b')
plot(x,yi,'r')
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!