how to import data from csv and plot?

17 views (last 30 days)
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');
Error using xlsread
Unable to open file 'baseline.csv'.
File '/users/mss.system.fjCCc6/baseline.csv' not found.
y= Array(:, 2);
x= Array (:, 1);
I'm attaching excel file also.
Thank you

Accepted Answer

Arif Hoq
Arif Hoq on 9 Nov 2022

Sign in to comment.

More Answers (2)

KSSV on 9 Nov 2022
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
  1 Comment
Ani Asoyan
Ani Asoyan on 9 Nov 2022
Thank you for the answer. However I would like to put the string data in the horizontal axis, so it appears 2022Q1, 2022Q2 instead of numbers. Also, did you change the column headers in the excel file?

Sign in to comment.

Kalpesh Bagmar
Kalpesh Bagmar on 9 Nov 2022
Hello Ani,
May be you can try following code snippet
a=a(4:end,:) % removing unwanted headings from data
b = cell2mat(a(:,2))
c = a(:,1)
  1 Comment
Ani Asoyan
Ani Asoyan on 9 Nov 2022
Thank you for your answer! I already accepted the prevous answer, but will also try your method. Thanks

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by