How can I remove quotes from a table?
10 views (last 30 days)
Show older comments
Hi,
I have a large csv file which I import to MATLAB by an user-prompt and store the information in a table. After storing the information in the table, I see that each value in the table gets appended inside a single quotation mark. How to remove this quotation mark from each element or more specifically, how can I avoid storing the information from the csv file without appending a quotation mark with every element? Screenshot & code attached.
BaseDir = 'C:\Users\mhaque7\Documents\MATLAB'; % Set as you need
[FileName, FilePath] = uigetfile('*.csv', ...
'Please choose an Excel file', BaseDir);
if isequal(FileName, 0)
disp('User aborted file choosing.');
return; % Assuming this is a function
end
File = fullfile(FilePath, FileName);
data_src=readtable(File) %importing data from the csv file into a table
0 Comments
Accepted Answer
dpb
on 12 Jul 2018
Because you used default conditions to readtable and didn't give it enough help to parse the data correctly; hence it read it all as cellstr--what the quotes are showing. They're not part of the data; they're just a visual cue ML uses to inform of what the data types are.
I built a sample of your file and read it as follows:
>> opt=detectImportOptions('haque.csv')
opt =
DelimitedTextImportOptions with properties:
Format Properties:
Delimiter: {','}
...
Variable Import Properties: Set types by name using setvartype
VariableNames: {'Time', 'x_DB_SEC', 'x_DB_USEC' ... and 1 more}
VariableTypes: {'double', 'double', 'double' ... and 1 more}
SelectedVariableNames: {'Time', 'x_DB_SEC', 'x_DB_USEC' ... and 1 more}
VariableOptions: Show all 4 VariableOptions
Access VariableOptions sub-properties using setvaropts/getvaropts
Location Properties:
DataLine: 3
VariableNamesLine: 1
RowNamesColumn: 0
VariableUnitsLine: 0
VariableDescriptionsLine: 0
opt.VariableOptions =
1x4 VariableImportOptions array with properties:
Variable Options:
(1) | (2) | (3) | (4)
Name: 'Time' | 'x_DB_SEC' | 'x_DB_USEC' | 'HRSTEST'
Type: 'double' | 'double' | 'double' | 'double'
FillValue: NaN | NaN | NaN | NaN
TreatAsMissing: {} | {} | {} | {}
QuoteRule: 'remove' | 'remove' | 'remove' | 'remove'
NB: the scan routine did figure out the variable names are in record 1 and the data starts at 3 and so recognized it as numeric. That's a big start. It did not, however, assign the second row to be the variable units. We can fix that pretty easily, however--
>> opt.VariableUnitsLine=2; % use 2nd record for units
>> t=readtable('haque.csv',opt) % _now_ we can read with this helper object
t =
3×4 table
Time x_DB_SEC x_DB_USEC HRSTEST
_____ ________ _________ _______
0 0 0 0
0.001 0 1000 0
0.002 0 2000 0
>> t.Properties.VariableUnits
ans =
1×4 cell array
{'sec'} {'sec'} {'usec'} {'hour'}
>>
and Voila! with the extra help you have both the units available and the numeric values as native doubles.
12 Comments
dpb
on 22 Jul 2018
hAx=gca;
hAx.XAxis.Exponent=0;
I don't know what you envision by " view multiple channels on the same x axis". You can plot as many lines on a given axis as you wish.
There are many plotting submissions on FEX for various things; perhaps something there may have been what was being referred to; I've no klew...
More Answers (0)
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!