Import mixed data from CSV file into MATLAB - matlab

I have a CSV file with data inside like:
10_09xyz,xy1,11,PX,....
...and I want to import it into MATLAB.
Is it possible to import the mixed data like 10_09xyz? Which format do I have to use?
I tried the following, but it failed:
formatSpec = %C%C%f%s%f';
T = readtable('XYZ.csv','Delimiter',',','Format',formatSpec);
The following warning appears:
"Variable names were modified to make them valid MATLAB identifiers."
Thanks for your help.

You can manually do it at least. Just use matlab open the folder and double click the csv file.
Please check my screenshop from matlab

Related

How to read a custom file format .fid

I have files with extension .fid
I want to read the data off of the file with matlab preferably. Is there anyway to do this with a custom file format like this?
If not, is there any other way I can transform this custom file format into something else? such as .csv?
Not familiar with this file type, but if it's human-readable, if you can open it in text editor and see the data, then there shouldn't be a problem. You can textscan to import data, if it's properly formatted, or fileread to import the entire file as string. You can even use uiimport to import data in interactive mode. Check MATLAB documentation for Data import and export

mat file to weka file

I am trying to use weka but it cannot. I have a .mat file that I generated in MATLAB and tried to convert it to WEKA format.
Things that I tried:
.mat to .xml (to use it in WEKA experimenter part) to do that I used the following code in here and WEKA gives error and says that "couldn't open experiment file"
tried to convert it as .arff file to use in WEKA explorer and followed the instructions here
But I have no idea about what classes and relation means in the code. I also couldn't find it on the internet. What are these two values meaning?
Best,
[ success_value ] = mat2arff( mat_filename, arff_filename, relation, classes )
You do not need an external function such as 'mat2arff'.
Weka can read *.csv files, so you can use csvwrite.
So, Assuming your mat file name is Matlab.mat and it contains a variable named test, you can do this:
>> load Matlab.mat
>> csvwrite('yourCSVfile.csv', test);

ReadTable in Matlab

When I use the readtable function I get the following error:
IVcellData = readtable('RiskModelData','Sheet',2,'Range','A1:A49')
Error using readtable (line 129) Invalid parameter name: Sheet.
Would appreciate if anyone could help me.
Have you renamed Sheet 2 to something else, e.g. Datafile? If so, you need to use this name (inside single quotes) not the sheet number instead of 2 in that call.
Also, you need to make a call to
opts = detectImportOptions(yourfilename)
before the call to readtable. I suspect this one is this cause as it is not recognising Sheet as a variable.
Took me a while to discover that lot, mostly empirical as the documentation is not clear on that point.
Keith
Looks like you need to define extension:
T = readtable(filename) creates a table by reading column oriented data from a file.
readtable determines the file format from the file name's extension:
.txt, .dat, or .csv for delimited text files
.xls, .xlsb, .xlsm, .xlsx, .xltm, .xltx, or .ods for spreadsheet files
try ReadModelData.xls or .xlsx

Importing data from text file and saving the same in excel

I am trying to read data from text file (which is output given by Tesseract OCR) and save the same in excel file. The problem i am facing here is the text files are in space separated format, and there are multiple files. Now i need to read all the files and save the same in excel sheet.
I am using MATLAB to import and export data. I even thought of using python to convert the files into CSV format so that i can easily import the same in MATLAB and simply excelwrite the same. But no good solution.
Any guidance would be of great help.
thank you
To read a text file in Matlab you can use fscanf or textscan then to export to excel you can use xlswrite that write directly to the excel file.

Matlab's Import Tool recognizes a column as numbers but generate %s in formatSpec

I use Matlab's Import Tool to generate a script that will take care of importing several CSV files with the same columns.
The Import Tool successfully manages to recognize the type of each column of my CSV file:
However, in the generated script, the same column are cast as strings (%s = string):
Any idea why?
Surprisingly it works fine with CSV files with fewer columns (it works with 70-column CSV files, but the issue arises with with 120-column CSV files). Here is one example of a CSV file that triggers the issue.
I use R2014b x64 with Windows 7 SP1 x64 Ultimate.
This is happening because one of the columns in your file contains data which contains numbers and text. The Import Tool is predicting that you're going to want to extract the numbers from this field, so it labels the column as 'NUMBER'. However, standard textscan doesn't allow for this, so the Import Tool must generate code to read in all of the data as text, and does the numeric conversion afterwards. The Import Tool is trying to help avoid errors using textscan.
The result of running the generated code is still numeric, as is shown in the Import Tool.
The specific column is labeled SEGMENT_ID in your example file. It contains data like:
l8K3ziItQ2pRFQ8
L79Y0zA8xF7fVTA
JYYqCCwRrigaUmD