readtable and invalid variable names - matlab

I have a script that converts a simulation data file that has variable names like force(1), velocity(2), etc. I have a script that converts the data file to CSV file and up to Matlab 2016b, I was able to import that CSV file to Workspace as a table by using 'readtable'. Readtable would issue a warning that says Matlab modifies those invalid variable names, but still import successfully by replacing the parentheses with underscores: a very minimum amount of modification.
Now with 2017b, readtable doesn't do what it used to do and the imported table variables have completely arbitrary names such as var1, var2, and such: a significant amount of modification.
How can I force readtable modify the variable names like it used to do? Here's a snap shot of the CSV file and it's the "S_Out_DE10(1)" variable name causing the havoc.
I can't use the GUI because I actually bring in multiple files and create table variables in a batch.
I open the CSV file, Cntr+S or Save button, say 'OK' when asked to keep the same format, and 'No' to the same question when closing the file; all without touching a single cell.
Here is a text format of some of the data:
TIME S_Out_DE10(1) Vph x_ehsv mA_ehsv
0 0 0 0 0
0.001 0 0 0 0
0.002 0 0 0 0
0.003 0 0 0 0
0.004 0 0 0 0
Now, the funny thing is if you copy/past the above and "save" it into a CSV file, that "saving" again makes it work.

Instead of using a CSV file with headers (for which it is not designed), you can use xlsread to directly read your Excel files instead.

Related

remove some string from a text file

I have a text file and I want to remove a part of text using Python 3.7.
Example:
helloooooooooooooo ### 122
How Are uuuuuuuuuuuuuuuuuuuuu?
GigaEthernet 0 1 0
GigaEthernet 1 2 0
GigaEthernet 2 1 3
helloooooooooooooo ### 122
helloooooooooooooo ### 122
i want the text file change to:
GigaEthernet 0 1 0
GigaEthernet 1 2 0
GigaEthernet 2 1 3
It maybe "FastEthernet" instead of GigaEthernet so we should consider "Ethernet" as a key word).
Instead of giving you a complete solution, I'll help on how to approach this kind of problem.
What do you have? A file.
What do you want? A modified file.
First, you need to load in the file as a data structure that you can work with, see: How to read a text file into a list or an array with Python
Second, you need to remove some lines, see: How to remove specific element in an array using python
Third, you need to save the changes to a file, see: Correct way to write line to file?
I hope that this helps.

Why does Matlab dbf-reader read certain integers wrong?

I use the matlab dbf reader available
here
I've noticed that three digit integers some times are read wrong.
Original data from dbf-file:
LAMAX,DTLD,1,599,727Q9,A,STANDARD,1,18,18,0,2359.5
But looking at the data in Matlab you see that 599 becomes 995.
Why is that?
'LAMAX','DTLD',[1],[995],'727Q9','A','STANDARD','1','18','18','0',
[2.3595e+03]
This is how I read the dbf file with matlab code
[dbfData, NAMES] = dbfread(path2file);
where dbfData is the actual data and NAMES are the field names in the dbf-file.
EDIT:
The dbf-file was created with INM
When I open the dbf file using OpenOffice the headers look like this
METRIC_ID,C,6 ; GRID_ID,C,8I_INDEX,N,3,0 ; J_INDEX,N,3,0 ; ACFT_ID,C,12 ; OP_TYPE,C,1 ; PROF_ID1,C,8 ; PROF_ID2,C,1 ; RWY_ID,C,8 ; TRK_ID1,C,8 ; TRK_ID2,C,1 ; DISTANCE,N,9,1
The distorted integers are stored with 3 digits numbers without decimals J_INDEX,N,3,0
Have you used the updated version of STR2DOUBLE2CELL?
From the link above:
STR2DOUBLE2CELL subfunction sometimes works incorrectly if number of digits in the input parameter is different

How to import large dataset and put it in a single column

I want to import the large data set (multiple column) by using the following code. I want to get all in a single column instead only one row (multi column). So i did transpose operation but it still doesn't work appropriately.
clc
clear all
close all
dataX_Real = fopen('dataX_Real_in.txt');dataX_Real=dataX_Real';
I will really appreciate your support and suggestions. Thank You
The sample files can be found using the following link.
When using fopen, all you are doing is opening up the file. You aren't reading in the data. What is returned from fopen is actually a file pointer that gives you access to the contents of the file. It doesn't actually read in the contents itself. You would need to use things like fread or fscanf to read in the content from the text data.
However, I would recommend you use dlmread instead, as this doesn't require a fopen call to open your file. This will open up the file, read the contents and store it into a variable in one function call:
dataX_Real = dlmread('dataX_Real_in.txt');
By doing the above and using your text file, I get 44825 elements. Here are the first 10 entries of your data:
>> format long;
>> dataX_Real(1:10)
ans =
Columns 1 through 4
-0.307224970000000 0.135961950000000 -1.072544100000000 0.114566020000000
Columns 5 through 8
0.499754310000000 -0.340369000000000 0.470609910000000 1.107567700000000
Columns 9 through 10
-0.295783020000000 -0.089266816000000
Seems to match up with what we see in your text file! However, you said you wanted it as a single column. This by default reads the values in on a row basis, so here you can certainly transpose:
dataX_Real = dataX_Real.';
Displaying the first 10 elements, we get:
>> dataX_Real = dataX_Real.';
>> dataX_Real(1:10)
ans =
-0.307224970000000
0.135961950000000
-1.072544100000000
0.114566020000000
0.499754310000000
-0.340369000000000
0.470609910000000
1.107567700000000
-0.295783020000000
-0.089266816000000

How to retrieve mat file data?

I have a mat file with 10 (columns) x 3 (rows) of data and I would like to retrieve these data to produce some readable output via certain functions. For example, the first column of data is 1 0 0 and the output will be Yes.
May I know how can I perform the first step, which is how to retrieve/read the data from the mat file which saved in laptop?
Assuming the name of your '.mat' file as 'xyz.mat' and the variable stored in .mat file had same name as the file.
load('xyz.mat') % loads xyz.mat into workspace.
if xyz(:,1)==[1;0;0],
answer='yes'
end
Note: Here I have assumed that array xyz was stored as xyz.mat , if the array name was different from filename given to the .mat file then you will have to use the array name in the if statement . e.g. if you stored an array named abcd as xyz.mat then when you use load('xyz.mat') the array gets loaded with its original name (abcd) and not the file name xyz

How can I copy columns from several files into the same output file using Perl

This is my problem.
I need to copy 2 columns each from 7 different files to the same output file.
All input and output files are CSV files.
And I need to add each new pair of columns beside the columns that have already been copied, so that at the end the output file has 14 columns.
I believe I cannot use
open(FILEHANDLE,">>file.csv").
Also all 7 CSV files have nearlly 20,000 rows each, therefore I'm reading and writing the files line by line.
It would be a great help if you could give me an idea as to what I should do.
Thanx a lot in advance.
Provided that your lines are 1:1 (Meaning you're combining data from line 1 of File_1, File_2, etc):
open all 7 files for input
open output file
read line of data from all input files
write line of combined data to output file
Text::CSV is probably the way to access CSV files.
You could define a csv handler for each file (including output), use getline or getline_hr (returns hashref) methods to fetch data, combine it into arrayrefs, than use print.