Create a power law fit from imported data
Mostra commenti meno recenti
I am importing data from an Excel spreadsheet on which I ultimately want to create a power law fit in MATLAB. In the code below, I removed my personal information in the filename.txt in the InputData line, so please ignore if you think this would create an error as written. The data is importing fine.
clear;
%Read the data for the fit
InputData = readtable('C:\MATLAB_Power_Law_Fitting.xlsx');
%remove any rows containing NAN
cleanData = rmmissing(InputData);
cleanX = cleanData.x;
cleanY = cleanData.y;
scatter(cleanData,'x','y');
ft = fit(cleanX,cleanY,'power1')
Here is the error I am getting on the last line.
_____________________________________________________
Error using fit>iFit (line 348)
NaN computed by model function, fitting cannot continue.
Try using or tightening upper and lower bounds on coefficients.
Error in fit (line 116)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in MatLab_Power_Law_Fits (line 16)
ft = fit(cleanX,cleanY,'power1');
________________________________________________________
There is no NAN data in cleanData nor are any of the values negative or zero. There is some repeating data, but this is research data.
Also, while I can create a scatter plot, MatLab throws up an error when I try to create a semilogx plot using the following line:
semilogx(cleanData,'x','y');
________________________________________________________
Error using semilogx
Data must be numeric, datetime, duration or an array convertible to double.
Error in MatLab_Power_Law_Fits (line 14)
semilogx(cleanData,'x','y');
__________________________________________________________
Thanks for any help.
1 Commento
Walter Roberson
il 21 Feb 2026
Back in R2021b, semilogx did not yet support table variables; that was added in R2022a (the release after yours)
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Detection in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
