fprintf filename error

조회 수: 1 (최근 30일)
Richard
Richard 2012년 3월 9일
Im using fprintf to write some data onto text files and using the following code to define the text file:
for i= 1:length(Table1);
filename{i} = fullfile(CorrFile,[Fieldnames{i} '.txt']);
fid{i} = fopen(filename{i},'wt');
end
Can anyone see why this returns an error;
Cell contents assignment to a non-cell array object.
It seems really strange because if I type:
filename = fullfile(CorrFile,[Fieldnames{1} '.txt']);
it works fine, It just doesnt like to store the filenames in cells. How could I make this work?
In addition, I've used the same code for making text files in another script (filename{}) and it worked fine. I don't understand what is going wrong.

답변 (1개)

Dr. Seis
Dr. Seis 2012년 3월 9일
Is Fieldnames a string? Do:
ischar(Fieldnames)
if you get a 1, then it is not a cellstr and therefore cannot use {}.
  댓글 수: 1
Richard
Richard 2012년 3월 9일
It is a cellstr that was why I was so confused about why it didn't work. Pre-allocating the cell before hand managed to work though. thanks

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by