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')

 Respuesta aceptada

Star Strider
Star Strider el 14 de Jun. de 2020

0 votos

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 comentarios

Sadra Sadra
Sadra Sadra el 15 de Jun. de 2020
Thank you
but I use matlab R2017a and readmatrix doesn't work.
Star Strider
Star Strider el 15 de Jun. de 2020
Then use xlsread or csvread.
Sadra Sadra
Sadra Sadra el 15 de Jun. de 2020
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 el 15 de Jun. de 2020
Thank a lot
It worked.
Star Strider
Star Strider el 15 de Jun. de 2020
Our pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 14 de Jun. de 2020

Comentada:

el 15 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by