textscan conversion specifier for 1 string N float - possible without specifying '%f' N times?
조회 수: 4 (최근 30일)
이전 댓글 표시
I want to read a texfile into a cellarray.
Each line contains one string at the beginning, followed by N floats; the N is quite large, around 50 numbers.
In the textscan docs I found a syntax like this:
fileID = fopen(filename);
C = textscan(fileID,'%s %f' %f' %f' %f' %f' %f' %f' %f' %f');
fclose(fileID);
is it possible to specify conversion without writing N times '%f'?
Thank you very much in advance,
Elke
댓글 수: 0
채택된 답변
dpb
2021년 7월 13일
편집: dpb
2021년 7월 13일
Unfortunately, the C syntax doesn't allow for a repeat count as does the Fortran FORMAT -- the MATLAB idiom to deal with it is still somewhat verbose but does eliminate having to explcitly code the repeated character. But the actual format string does indeed, have to have it repeated literally, unfortunately.
fmt=['%s' repmat('%f',1,N)];
C=textscan(fid,fmt);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!