최근 포토로그


Error using ==> sprintf. Function is not defined for sparse inputs. Programming

scrapped from :  http://www.mathworks.com/support/solutions/en/data/1-20J9XR/index.html?product=ML&solution=1-20J9XR

Problem Description:

When I execute the following commands:
s=sparse(eye(5,5));
dlmwrite('mydata.dat',s);
I receive the following result:
??? Error using ==> sprintf
Function is not defined for sparse inputs.
Error in ==> dlmwrite at 172
str = sprintf(format,m(i,:));
However, the above commands works without errors in MATLAB 6.5.1 (R13SP1) and a file 'mydata.dat' is created.

Solution:

Thisis not a bug. The error message you are receiving is issued by theSPRINTF function, which does not accept sparse matrices as input. Towork around this issue, convert the sparse matrix to a full matrixbefore using DLMWRITE. Here are the steps:
s=sparse(eye(5,5));
dlmwrite('mydata.dat',full(s));



덧글

댓글 입력 영역