Read Excel File into code

4 visualizaciones (últimos 30 días)
Robyn Macartney
Robyn Macartney el 14 de Nov. de 2019
Comentada: Robyn Macartney el 14 de Nov. de 2019
Hi I have created code to determine a true/false response based on multiple user input data which is stored in an excel file. Is there a way I can write some code to get the data within the excel file to be entered into the MatLab inputs?
I have attempted using csvread function and can't get this to work. Any suggestions welcome, thank you!

Respuestas (1)

hector martinez
hector martinez el 14 de Nov. de 2019
Csvread will only read an excel file with numeric values. If your values aren't numeric or if you have column names that aren't numeric, it won't work. You can get around this by skipping the first row of your data so it won't read your column headers.
csvResponse = csvread('csvFile',1,0)
and changing your true/false values to 1/0.
I prefer using readtable, because your data can be any type. Additionally, column headers can be used as variables, and you can use dot notation to access values in the table.
tableResponse = readtable('csvFile');
% Replace Column1 with the name of whatever column your trying to access, x is the index of the value you want.
someResponse = tableResponse.Column1(x)
My favorite feature is being able to gather data from one column based on values from a different column, such as:
anotherResponse = tableResponse.Column1(tableResponse.Column2 == someCondition)
This says get the values from Column1 where the values in Column2 equal someCondition.
  1 comentario
Robyn Macartney
Robyn Macartney el 14 de Nov. de 2019
Thanks, I managed to get my file to be read into the code as a matrix using readmatrix function. This matrix is 13 columns of variables for a number of subjects, is there a way I would be able to write code to enable each row to be read and the variables entered into my condition statements? And repeat for each subject case?

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by