Hi!
I have several csv files with the information strutured as
"1";"2";"3";
and I need to access the informations as matrixes.
I have tried readmatrix, and readmtx, but the " " are really bothering me. When I tried readtable, it gets the information but doesn't save it as a number, so potentially I could transform the table to a matrix, but I haven't been able to.
I tried to use:
T2= replace(T1,' " ',' ')
Any help would be appreciated! Thanks!!

댓글 수: 4

Rik
Rik 2021년 3월 18일
str2double will probably work, otherwise you could read the file yourself e.g. with readlines (R2020b or later), fileread, or readfile (from the FEX or through the AddOn-manager).
Then you can parse the text yourself.
Stephen23
Stephen23 2021년 3월 18일
편집: Stephen23 2021년 3월 18일
Please upload a sample file by clicking the paperclip button.
Please specify your MATLAB release in the Release field on the right of this page.
This is the one I have been using as a test
I updated my version of matlab and now it works
Thank you so much!!

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephen23
Stephen23 2021년 3월 18일
편집: Stephen23 2021년 3월 18일

0 개 추천

Using string manipulation:
str = fileread('prueba1.csv');
str = strrep(strrep(str,'"',''),';',' ');
mat = sscanf(str,'%f',[3,Inf]).'
mat = 5×3
234 42 243 456 34 23 678 75 765 456 355 65 647 78 75
Or using TEXTSCAN:
fmt = '%f%f%f';
opt = {'Delimiter','";', 'MultipleDelimsAsOne',true, 'CollectOutput',true};
fid = fopen('prueba1.csv','rt');
tmp = textscan(fid,fmt,opt{:});
fclose(fid);
mat = tmp{1}
mat = 5×3
234 42 243 456 34 23 678 75 765 456 355 65 647 78 75

추가 답변 (1개)

Seth Furman
Seth Furman 2021년 3월 18일
편집: Seth Furman 2021년 3월 18일

0 개 추천

If you use readtable, you can convert the table to a matrix by using the table2array function.
For example,
>> readtable('prueba1.csv')
ans =
5×3 table
Var1 Var2 Var3
____ ____ ____
234 42 243
456 34 23
678 75 765
456 355 65
647 78 75
>> table2array(ans)
ans =
234 42 243
456 34 23
678 75 765
456 355 65
647 78 75

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2021년 3월 18일

편집:

2021년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by