unable to prevent whitespaces while preforming readmatrix

15 vues (au cours des 30 derniers jours)
Robert Scott
Robert Scott le 8 Août 2021
So i have repeatibly tried to prevent the readmatrix function from brining ing white spaces while reading a csv file.
It does not appear to make any difference what setting i change, i still get white spaces.
I am doing the following. What am i doing wrong? Can someone lend a hand please
import_options = setvartype(import_options,'char');
import_options.ConsecutiveDelimitersRule = 'split';
import_options.Whitespace = '\b\t';
import_options = setvaropts(import_options,'WhitespaceRule','trim')
array = readmatrix(filepath,import_options)

Réponse acceptée

Robert Scott
Robert Scott le 8 Août 2021
ok well if anyone else is interested i answered this myself
set this with a space in single quotes and it will work
import_options.Whitespace = ' ';

Plus de réponses (2)

Robert Scott
Robert Scott le 8 Août 2021
I have done some more digging with this. So when i do a getvaropts call there is no field called WhitespaceRule
Apparently, there are two different things here.
Under the main detectimportoptions call
There is a feild called Whitespace, that tells what characters matlab will treat as a white space
Then if you do a getvaropts call there should of been a field for something called WhitespaceRule
I have tried to set that to trim which should be the default anyway. Now for some reason that field is missing. I am not sure if its because my variables are of type char?
Does anyone have any ideas here.

Robert Scott
Robert Scott le 8 Août 2021
Also, s i investigate more
So when i open my csv in a test file i see the following
My delimiter is a ","
However the data goes something like this
'data' data' data
So there is a space at the end of every delimter and in between the new data. Which is what matlab must be seeing as a space.
What can i do about that?


En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by