unable to prevent whitespaces while preforming readmatrix

조회 수: 17 (최근 30일)
Robert Scott
Robert Scott 2021년 8월 8일
답변: Robert Scott 2021년 8월 8일
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)

채택된 답변

Robert Scott
Robert Scott 2021년 8월 8일
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 = ' ';

추가 답변 (2개)

Robert Scott
Robert Scott 2021년 8월 8일
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 2021년 8월 8일
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?

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by