How can I load this file?

Hi everyone,
I should load this file.
I tried in this way but I can't plot data because I have text and number together.
data = readtable('casestudy.csv', 'ReadVariableNames', true)
Can anyone help me kindly?
Thank you in advance!

2 comentarios

Scott MacKenzie
Scott MacKenzie el 23 de Abr. de 2021
Yes, your table contains text and numeric data. What are you trying to plot? The 2nd column (S_Dev) contains numeric data. Here's a plot:
T = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/593980/casestudy.csv')
plot(T.S_Dev);
Pul
Pul el 23 de Abr. de 2021
I should plot the 1st column (Timee) and the 2nd column (S_Dev).
Thank you

Iniciar sesión para comentar.

 Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 23 de Abr. de 2021

0 votos

How about this:
T = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/593980/casestudy.csv', 'ReadVariableNames', true)
plot(T.S_Dev);
ax = gca;
ax.XLabel.String = 'Timee';
ax.YLabel.String = 'S Dev';
ax.XTickLabels = T.Timee;
f = gcf;
f.Color = 'w';
f.Units = 'normalized';
f.Position = [.2 .2 .6 .5]; % widen a bit, so tick labels can be read

3 comentarios

Pul
Pul el 23 de Abr. de 2021
Editada: Pul el 23 de Abr. de 2021
Thank you so much!
Just another question: how can I convert text to numerica data in this case?
Scott MacKenzie
Scott MacKenzie el 23 de Abr. de 2021
Well, text is text. You can't convert "2009-2010" to numeric data. You could divide the text into character arrays for each part and then convert:
>> c = cell2mat(T.Timee)
c =
7×9 char array
'2009-2010'
'2010-2011'
'2011-2012'
'2012-2013'
'2013-2014'
'2014-2015'
'2015-2018'
>> n = [str2num(c(:,1:4)) str2num(c(:,6:9))]
n =
2009 2010
2010 2011
2011 2012
2012 2013
2013 2014
2014 2015
2015 2018
Pul
Pul el 23 de Abr. de 2021
Okay, thank you very much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

Pul
el 23 de Abr. de 2021

Comentada:

Pul
el 23 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by