Hi, I have one question.
I have a CSV file that I want to fit the data in columns 30 and 33 and I wrote the fit function to draw fit plot and data plot, but I don't know how to convert CSV file columns to a vector and give it to the function as input.
The function code is shown below.
I need your help. Thank you
function y = fit(x0,y0)
X1 = [ones(length(x0),1) x0'];
b = X1\y0'
y = b(1) + x0*b(2)
slope = b(2)
intercept = b(1)
plot(x0,y0,'o')
hold on
plot(x0,y,'--r')

 採用された回答

Star Strider
Star Strider 2020 年 6 月 14 日

0 投票

Use the readmatrix or other appropriate function, then go from there:
D = readmatrix('student-mat.csv');
Note that ‘D’ is a (395x33) matrix, so you need to figure out what columns you want to use.

6 件のコメント

Sadra Sadra
Sadra Sadra 2020 年 6 月 15 日
Thank you
but I use matlab R2017a and readmatrix doesn't work.
Star Strider
Star Strider 2020 年 6 月 15 日
Then use xlsread or csvread.
Sadra Sadra
Sadra Sadra 2020 年 6 月 15 日
Can you say how to use it to transform column to vector in Matlab?
Walter Roberson
Walter Roberson 2020 年 6 月 15 日
Use readtable (you might need to use detectImportData as well)
filename = 'student-mat.csv';
opt = detectImportOptions(filename);
D = readtable(filename, opt);
G3 = D.G3;
absences = D.absences;
Sadra Sadra
Sadra Sadra 2020 年 6 月 15 日
Thank a lot
It worked.
Star Strider
Star Strider 2020 年 6 月 15 日
Our pleasure!

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by