How to reform cell into a vector of strings and text
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I want to read in a excel with the first cell of each row of the form:
2020-09-02 00:00:00.7770000,"OLW218","Pickling","Water lock Off-time PV (Sec)",105,,,"Good"
(this is all in one cell)
and replace it with a vector of the form
[0.777,"OLW218","Pickling","Water lock Off-time PV (Sec)",105,"Good"]
or a form where I can for example have: vector(6) = "Good".
If I use xlsread or save the excel as txt file it is imported as a cell {"2020-09-02 00:00:00.7770000,"OLW218","Pickling","Water lock Off-time PV (Sec)",105,,,"Good""}. I tried the split command, but I can't get the result I want.
2 件のコメント
dpb
2021 年 10 月 21 日
Why don't you use the Excel whizard and convert/split the text there, just out of curiosity?
How did the file get created in this manner in the first place?
The easiest problem to solve is the one that don't create in the first place...going back to the beginning might be the simplest fix.
回答 (1 件)
dpb
2021 年 10 月 21 日
Two of many ways to deal with the cellstr --
As string array
>> S=string(split(C,',')); S=S(S~="")
S =
6×1 string array
"2020-09-02 00:00:00.7770000"
""OLW218""
""Pickling""
""Water lock Off-time PV (Sec)""
"105"
""Good""
>>
or as cellstr
>> CC(~cellfun(@isempty,CC))
ans =
6×1 cell array
{'2020-09-02 00:00:00.7770000' }
{'"OLW218"' }
{'"Pickling"' }
{'"Water lock Off-time PV (Sec)"'}
{'105' }
{'"Good"' }
>>
Alternatively, use textscan and convert the fields directly. Will leave as "exercise for student"
参考
カテゴリ
Help Center および File Exchange で Text Data Preparation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!