Illegal use of reserved keyword "for".
3 views (last 30 days)
Show older comments
I have the following code which replaces text when I directly put a string in the "nextLine" statement, however when I try to input elements of a cell array with a delimiter the function breaks at the "for" statement. Can anybody please explain how I am using this incorrectly, or direct me to a better way to format this input?
Thank you for your time.
function replaceLine(inputPath,outputPath)
inputFile = fopen(inputPath,'r');
outputFile = fopen(outputPath,'w');
while ~feof(inputFile)
nextLine = fgets(inputFile);
if any(contains(strsplit(nextLine,'3 3'),'3 ')) %first repsonses
newLine = '' for n = 1:length(cell{1,1})
newLine = [newLine '' cell{1,1}(n)]
end
end
fprintf(outputFile,nextLine);
end
fclose(inputFile);
fclose(outputFile);
end
0 Comments
Answers (1)
Stephen23
on 6 Jun 2018
Edited: Stephen23
on 6 Jun 2018
Instead of this
newLine = '' for n = 1:length(cell{1,1})
You should do this:
newLine = '';
for n = 1:length(cell{1,1})
(adding a semicolon or comma would be sufficient, but putting the code on two lines is much clearer)
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!