Matlab Doesn't Recognize Fits Files (evalin, sprintf)?
조회 수: 4 (최근 30일)
이전 댓글 표시
I need my script to read in five images (capture_667.fit... capture_671.fit), and name them image667... image 671. I have the following code:
for j = 667:671
evalin('base', sprintf('[ image%03d ] = fitsread(capture_%03d.fit);', j, j));
end
However, I get this error message:
.
'Undefined variable "capture_667" or class "capture_667.fit".
Error in Try_Sprintf_Evalin_New (line 5) evalin('base', sprintf('image%03d = fitsread(capture_%03d.fit);', j, j));'
.
All of the files I'm trying to read in are in the right folder. Furthermore, if I try to open these files manually, I get this message:
.
'Error using open (line 162) CFITSIO library error (412); datatype conversion overflow'
.
What's stopping my code from working? And what is a datatype overflow? I've looked online for a definition but with no luck.
NB: This task was set by demonstrators at university. I HAVE to complete it using sprintf, evalin, and fitsread.
댓글 수: 0
채택된 답변
Thorsten
2015년 11월 16일
You forgot to put the image name into quotation marks to mark them as strings; note that you have to use two because they appear inside quotation marks:
evalin('base', sprintf('image%03d = fitsread(''capture_%03d.fit'');', j, j));
A better way would be without evalin
for j = 667:671
filename = sprintf('capture_%03d.fit', j);
I{j} = fitsread(filename);
end
You can then work with I{667}, for example. One drawback of the evalin approach is that it is more error prone (you've just made the experience).
추가 답변 (2개)
Walter Roberson
2015년 11월 16일
If you need your code to do that, then it is time to renegotiate the requirements with who-ever imposed that constraint. Creating variables on the fly is not recommended at all.
댓글 수: 3
Walter Roberson
2015년 11월 16일
Well now you begin to see why we do not recommend using eval() or evalin() .
Is the requirement definitely for evalin()? You cannot use assignin() instead?
참고 항목
카테고리
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!