How to get Matlab read my char file in excel?

Let say I have a csv file and have a list of char inside.
Capture1.PNG
I want to read it as:
Capture2.PNG
x=dlmread('test10042019_char.csv');
y=csvread('test10042019_char.csv');
But not working.
>> x=dlmread('test10042019_char.csv',' ', 1,0);
Error using dlmread (line 143)
Mismatch between file and format string.
Trouble reading 'Numeric' field from file (row number 1, field
number 1) ==> ,\n
Thank you.

Answers (1)

dlmread shouldn't work. From the documentation: "(Not recommended) Read ASCII-delimited file of numeric data into matrix".
"M = dlmread(filename) reads an ASCII-delimited numeric data file into matrix M. The dlmread function detects the delimiter from the file and treats repeated white spaces as a single delimiter."
Your data is not numeric. It doesn't matter what options you add, it won't be able to reach text.
csvread has the same issue.
"M = csvread(filename) reads a comma-separated value (CSV) formatted file into array M. The file must contain only numeric values."
I would suggest using readtable
x = readtable('test10042019_char.csv')

8 Comments

Though not a recommended function, you could also try using xlsread.
[~,txt] = xlsread('test10042019_char.csv')
Matlaber's "Answer" moved here:
Thanks.
x = readtable('test10042019_char.csv')
It end up this:
Thank you
I had tried:
[~,text] = xlsread(test10042019_char.csv);
text = char(text);
It said:
Undefined function or variable 'cls'.
Thank yuou
There is no "cls" in the posted code anywhere. Please post the complete error message.
Do not redefine the important Matlab function "text" as a variable.
I guess, you forgot the quotes:
[~,text] = xlsread('test10042019_char.csv');
% ^ ^
Creating a CHAR matrix is a bad idea. Prefer to work with cell strings or better modern string objects.
Thanks.
It works. However
Warning: Function filter has the same name as a MATLAB builtin. We suggest
you rename the function to avoid a potential name conflict.
Warning: Function filter has the same name as a MATLAB builtin. We suggest
you rename the function to avoid a potential name conflict.
I have no idea why this happened.
Secondly, can you explain more on how to work with cell strings or better modern string objects.
Thanks.
It won't help you with cells and strings, but I suggest you take some time to go through MATLAB Onramp.
I know about the MATLAB Onramp before.
I just need some help in this.
The message means, that you have created a function file called "filter.m", but this is a built-in function already. This can and will cause conflicts. Do not shadow built-in function by user-defined functions or variables.
You just need help in what? Strings, cell strings, char vectors and char matrices are explained exhaustively in the Getting Started chapters of the documentation and I assum in Matlab's OnRamp also. It would be rather inefficient, if I explain more, if there is a very good complete documentation already. Please learn the basics from there and ask a specific question on demand.

Sign in to comment.

Categories

Tags

Asked:

on 10 Apr 2019

Commented:

Jan
on 12 Apr 2019

Community Treasure Hunt

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

Start Hunting!