Replace the first line and save to a file in Matlab? -
I'm trying to do this in Matlab, but it shows that
Error using fgets Invalid file identifier to use a Fopen to generate a valid file identifier
Can someone help solve this problem? Thanks in advance.
The following are my syntax:
function [] = replaceStr (fidInFile, DIF (k), DIF (k + 1)) k = 1: 100 fidInFile = fopen (['Sum' num2str (k) '.inp'], 'r'); FidOutFile = fopen (['amount' number 2str (k + 1) '.inp'], 'w'); NextLine = fgets (fidInFile); While the next line & gt; = 0 next line = strupp (next row, ['data = dif' num2str (k) '' dat '], [' data = dif 'num2str (k + 1)' .dat ']); Fprintf (fidOutFile, '% s', next line); NextLine = fgets (fidInFile); End fclose (fidInFile); Fclose (fidOutFile);
To read in a file, replace the first line, and type it back to you You can do the following:
% open files fidIn = fopen ('test.txt'); FidOut = fopen ('test2.txt', 'w'); Read in the% Tline = fgets (fidIn) file; Index = 1; Where ischar (tline) data {index} = tline; Tline = fgets (fid); Index = index + 1; First line data instead of end% {1,1} = 'some more'; Write on the second file for% l = data fprintf (fidOut, '% s \ n', l {1,1}); End fclose (fidIn); Fclose (fidOut);
The error you are receiving may be invalid, because the name or path of the file you are using is invalid.
Comments
Post a Comment