CSV file that needs to be run through MATLAB?

New to MATLAB. I have been given data in a CSV file that needs to be run through a given MATLAB code and I do not know where to even start. Can anyone help me?

6 comentarios

Stephen23
Stephen23 el 9 de Nov. de 2018
Editada: Stephen23 el 9 de Nov. de 2018
Duplicate:
"Can anyone help me?"
You can help you, by reading the links that Star Strider gave you. They show how to import data. If you tried them and something did not work then please add comments to that question, showing exactly what you tried.
It does not help to simply ask the same question again and again.
Kristine McKay
Kristine McKay el 9 de Nov. de 2018
I have looked through the links and they don't make sense to me.
Steven Remington
Steven Remington el 12 de Nov. de 2018
Hi Kristine,
If you are looking to read from a CSV file, I would recommend starting with the "readtable" function in MATLAB. This should be able to read in the data and store it in a MATLAB table so that you can use it.
More information about this function can be found at the link below: https://www.mathworks.com/help/matlab/ref/readtable.html
Kristine McKay
Kristine McKay el 12 de Nov. de 2018
Hi Steven,
I have tried this but the following error has appeared.
Error in line 3
T = readtable('cardio_test_2, Value');
In the description the file is definitely a Microsoft Excel Comma Separated Values File (.csv).
The file is on a memory pen so I tried using the full path name and this doesn't change the error... What do you think?
Walter Roberson
Walter Roberson el 12 de Nov. de 2018
Does the file name really have a comma and space in it? And does it really not have a file extension?
I speculate that you are interested in the column named Value in the file cardio_test_2.csv
T = readtable('cardio_test_2.csv');
T.Value
Kristine McKay
Kristine McKay el 12 de Nov. de 2018
Hi Walter,
This is what I now have currently but MATLAB is ignoring this line and jumping straight to the code
T = readtable('E:\Uni\Final\MATLAB\Assignment 1\cardio_test_2.csv');

Iniciar sesión para comentar.

 Respuesta aceptada

Andrew Padilla
Andrew Padilla el 12 de Nov. de 2018
Editada: Andrew Padilla el 12 de Nov. de 2018

0 votos

Kristine,
Have you tried loading in the data using the csvread() function?
If you have a csv file that is named "Test.csv" you can import it to your workspace using the following:
data = csvread('Test.csv');

13 comentarios

Kristine McKay
Kristine McKay el 12 de Nov. de 2018
Is this for the full file name?
Kristine McKay
Kristine McKay el 12 de Nov. de 2018
Come back with Error in B00690215_Assignment_1 (line 4)
data = csvread('cardio_test_2');
Kristine McKay
Kristine McKay el 12 de Nov. de 2018
Error in B00690215_Assignment_1 (line 3)
data = csvread('E:\Uni\Final\MATLAB\Assignment 1\cardio_test_2.csv');
Walter Roberson
Walter Roberson el 12 de Nov. de 2018
What is the complete error message?
Have you posted an example of the csv file you are dealing with?
Kristine McKay
Kristine McKay el 12 de Nov. de 2018
Please see attached CSV file. I have moved on to try to use
T = table
T = table ('val1','val13');
Kristine McKay
Kristine McKay el 12 de Nov. de 2018
Walter, full error is
Error in csvread (line 48)
m=dlmread(filename, ',', r, c);
Error in B00690215_Assignment_1 (line 3)
data = csvread('E:\Uni\Final\MATLAB\Assignment 1\cardio_test_2.csv');
Andrew Padilla
Andrew Padilla el 12 de Nov. de 2018
Editada: Andrew Padilla el 12 de Nov. de 2018
Kristine,
you need to include the property of the file in the csvread() function. In other words, add the .csv.
Try this,
data = csvread('cardio_test_2.csv');
Kristine McKay
Kristine McKay el 12 de Nov. de 2018
Error in B00690215_Assignment_1 (line 3)
data = csvread('cardio_test_2.csv');
Andrew Padilla
Andrew Padilla el 12 de Nov. de 2018
Could you send a screenshot of your data set? I think it has something to do with the actual set of data that you are trying to work with.
Kristine McKay
Kristine McKay el 12 de Nov. de 2018
A screenshot of the CSV file?
Kristine McKay
Kristine McKay el 12 de Nov. de 2018
Walter Roberson
Walter Roberson el 13 de Nov. de 2018
It has a text column. It cannot be used with csvread() or dlmread(). You will need to use readtable() or textscan()
Kristine McKay
Kristine McKay el 13 de Nov. de 2018
Thanks all! This has helped!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 9 de Nov. de 2018

Comentada:

el 13 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by