how to import data from csv and plot?
241 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone!
I want to import excel dataset (csv file) to matlab and plot.
The first column includes string variables like "2022Q1" , "2022Q2", etc.
The second column is regular data. How can I import that csv and plot 2nd column with respect to 1st column (so the strings be the horizontal axis).
I've tried something like this but doesn't work.
[Array, str, raw]=xlsread('baseline.csv');
y= Array(:, 2);
x= Array (:, 1);
plot(x,y)
I'm attaching excel file also.
Thank you
0 commentaires
Réponse acceptée
Arif Hoq
le 9 Nov 2022
A=readtable('baseline.csv','VariableNamingRule','preserve');
xaxis=table2array(A(:,1));
datavalue=table2array(A(:,2));
C=categorical(xaxis);
plot(C,datavalue)
xtickangle(90)
3 commentaires
Plus de réponses (2)
KSSV
le 9 Nov 2022
T=readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1186578/baseline.csv');
X=T.(1);
Y=T.(2);
plot(Y)
Kalpesh Bagmar
le 9 Nov 2022
Hello Ani,
May be you can try following code snippet
[a]=readcell('baseline.csv')
a=a(4:end,:) % removing unwanted headings from data
b = cell2mat(a(:,2))
c = a(:,1)
bar(b)
set(gca,'xticklabel',c)
Voir également
Catégories
En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!