Textscan, dlmread, and importdata all not working

조회 수: 5 (최근 30일)
Skyler Castillo-Wilson
Skyler Castillo-Wilson 2018년 6월 29일
댓글: Skyler Castillo-Wilson 2018년 6월 29일
I have a very simple text file comprised of 1's and 0's. I have tried to read it into MATLAB with every function I can find, but nonetheless I get an error of some form. dlmread seems the most promising, but it throws a "Mismatch between file and format character vector." error. textscan did not work as it created a 1X1 cell with all of the data in it, and trying A = A{:} also did not work, similar error with importdata. Any help would be much appreciated.
  댓글 수: 6
Stephen23
Stephen23 2018년 6월 29일
편집: Stephen23 2018년 6월 29일
" textscan did not work as it created a 1X1 cell with all of the data in it"
Why do you think that having the data in one cell is a problem? What is important is how you called textcan and the content of the cell. But unless you give us this information we will just be guessing...
Skyler Castillo-Wilson
Skyler Castillo-Wilson 2018년 6월 29일
Sorry, the goal is to delineate the data so that each value of 1 or 0 is parsed into its own cell. I plan on for looping through each individual value, and I don't think thats possible if its all in one cell (if it is that would be amazing).

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

채택된 답변

Adam Danz
Adam Danz 2018년 6월 29일
편집: Adam Danz 2018년 6월 29일
See how this works for you,
fid = fopen('FakeData.txt');
t = textscan(fid, '%s');
fclose(fid)
t2 = cell2mat(cellfun(@str2double, t, 'uniformoutput', false));
  댓글 수: 8
Adam Danz
Adam Danz 2018년 6월 29일
Yeah, my downloaded txt file also has those weird chars.
Skyler Castillo-Wilson
Skyler Castillo-Wilson 2018년 6월 29일
Update for those who helped: Naturally, the only issue was compatibility between what a number means to my PC keyboard vs. my MacBook Pro. That messed with the text file just enough to ruin all of those functions. Problem resolved!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by