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?
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개)

카테고리

태그

질문:

2020년 6월 14일

댓글:

2020년 6월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by