I have a text file which was created in the "Current Folder" window. Now, I want to re-save this file in another direction (or copy the file as I did). This is my code:
[FileName,PathDir] = uiputfile('log_MCES.txt','Save Calculation Notes');
if isequal(FileName,0) || isequal(PathDir,0)
else
copyfile(FileName, PathDir)
end
The original file it contains the following:
Note 1: [Graphical Representation] A cost node is invisible for an energy node.
=====================================
Note 2: An Optimum Solution has been Achieved.
=====================================
But the copied one is:
Note 1: [Graphical Representation] A cost node is invisible for an energy node.=====================================Note 2: An Optimum Solution has been Achieved.=====================================
As shown, the order of the texts has been changed and I don't know why?

 채택된 답변

Steven Lord
Steven Lord 2015년 8월 27일

1 개 추천

The order of the text hasn't changed. It's being displayed with fewer newlines, but I suspect that's because you've opened the file in Microsoft Notepad. What does the file look like if you open it in the MATLAB Editor?

댓글 수: 5

Walter Roberson
Walter Roberson 2015년 8월 28일
It would be expected that the copy would end up identical to the original in content (but not necessarily in metadata such as ownership)
Haitham
Haitham 2015년 8월 28일
편집: Haitham 2015년 8월 28일
Yes exactly Steven, when I opened both files with Microsoft Notepad they being displayed with fewer newlines but with MATLAB Editor both of them are OK (as displayed in the Edit Text box). Is there a way to make the file displayed as it is in the MATLAB Editor?
Walter Roberson
Walter Roberson 2015년 8월 28일
Unfortunately copyfile is built-in so I cannot see what it is doing. The behavior you describe is what might be expected if a program opened the source file in text mode and read a line at a time and write the line to a destination opened in binary mode. That implementation is not plausible, though, as it would be much more likely to call upon operating system facilities to copy the files.
Haitham
Haitham 2015년 8월 29일
Thank you Walter.
Walter Roberson
Walter Roberson 2015년 8월 29일
Haitham, is it possible that you are using MATLAB R14SP2 or earlier?

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

질문:

2015년 8월 27일

댓글:

2015년 8월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by