Write an array of data to multiple text file but it shows error
Info
This question is closed. Reopen it to edit or answer.
Show older comments
x =rand(10,1);
for i=1:10
A = x*i;
textFilename = ['akg_' num2str(i) '.txt'];
fid=fopen(textFilename,'w');
fprintf(fid,'%f\n',A(i));
fclose(fid);
end
I get the error
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
error in xyz (line 6)
fprintf(fid,'%f\n',A(i));


4 Comments
per isakson
on 10 Feb 2018
Edited: per isakson
on 10 Feb 2018
Replace
textFilename = ['akg_' num2str(i) '.txt'];
by
textFilename = fullfile('akg_',[num2str(i),'.txt']);
AKHILA GOUDA
on 10 Feb 2018
per isakson
on 10 Feb 2018
I guess you don't have write permission in the current directory

Write to a different directory
AKHILA GOUDA
on 10 Feb 2018
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!