Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

How to load a csv file as a datamatrix in matlab?

Date: 2022-12-12 13:33:34

I try to load a csv file in matlab to use a certain column as a vector for a OLS estimation. However, my csv looks like: 

   Date            KCFSI
13  2004-02-01  -0.67
14  2004-03-01  -0.58
15  2004-04-01  -0.57
16  2004-05-01  -0.49
17  2004-06-01  -0.67
... 

and I want to have the the column KCFSI as a vector.

 

I tried: 

 

 

x=fopen('kcfsi.csv'); kcfsi=x(:,2);

But I don't even get a matrix for my x. Just get as value : "14" for whatever reason. I want to have something like "2x100" 

Answers: 

csvread cannot open csv files containing non-Numeric values as stated in the documentation.

The file must contain only numeric values.

So you should use textscan as explained in this answer : https://stackoverflow.com/a/19613301/11756186

Alternatively you can use the readtable built-in function 

 

csvtable = readtable('kcfsi.csv'); kcfsi_array = csvtable.KCFSI; %Column vector with the content of the KCFSI column


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com