Hello – I would like to plot seismic data with a y range from 10 -7 to 10-1 (m*s) and an x range from 1 to 10 000 (Hz) on a log log plot. Than I would like to do a linear regression on this but basic fit gives a line not reflective of the data. Could you please advise what is the best technique to use ?
Any help will be much appreciated.

 採用された回答

dpb
dpb 2015 年 2 月 12 日
編集済み: dpb 2017 年 11 月 29 日

1 投票

X=log10(x); Y=log10(y); % convert both variables to log's
b=polyfit(X,Y,1); % estimate coefficients
yhat=10.^[polyval(b,[X(1) X(end)])]; % evaluate at end points
loglog(x,y)
hold on
loglog([x(1) x(end)],yhat) % add fitted line

7 件のコメント

Rookshana Trollope
Rookshana Trollope 2015 年 2 月 12 日
Thank you I will try this
Rookshana Trollope
Rookshana Trollope 2015 年 2 月 12 日
It says unexpected matlab error. must I ignore line 4 and 5 ?
Rookshana Trollope
Rookshana Trollope 2015 年 2 月 12 日
I get as far as b but yhat gives me an unexpected matlab error.
dpb
dpb 2015 年 2 月 12 日
oops, use the "dot" operator .^ to take element-by-element power
Rookshana Trollope
Rookshana Trollope 2015 年 2 月 13 日
編集済み: Rookshana Trollope 2015 年 2 月 13 日
Ok will try - Thanks I dit that and nothings happening after 30 min. But it looks
like its still trying so it must be in a loop. Can I load an screen image for you to look at ? will really appreciate your help.
dpb
dpb 2015 年 2 月 13 日
Note the message at the bottom -- "Continue entering statement"
It's waiting for something but I can't tell what--the paren's look to be balanced unless my old eyes are missing one.
Try another CR or two; if that doesn't finish the line then Ctrl-C out back to the command prompt and try again...either there's something in the commandline processor that's hidden or the graphics engine in a newer release has gotten hung up or somesuch; with a 2-length vector it would take only a few seconds at most.
Thomas Schragl
Thomas Schragl 2017 年 11 月 29 日
when trying the code noted above I found that there is one ] missing in line 3
right now:
yhat=10.^[polyval(b,[X(1) X(end)]);
and should be:
yhat=10.^[polyval(b,[X(1) X(end)])];
note the ] before the ;

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Logging についてさらに検索

質問済み:

2015 年 2 月 12 日

編集済み:

dpb
2017 年 11 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by