필터 지우기
필터 지우기

how to convert or generate prn files to xlsx files

조회 수: 40 (최근 30일)
neela
neela 2024년 7월 29일
편집: dpb 2024년 8월 3일 13:29
i have .prn files i want to covert those files to xlsx files
  댓글 수: 7
Walter Roberson
Walter Roberson 2024년 7월 30일
data = readcell('C:\Users\vzmglb\Desktop\29july2024\CITYRUN_LK0_STOICH_1.prn', 'filetype', 'text');
writecell(data,'File1.xlsx')
winopen('File1.xlsx')
I am not completely clear as to whether the username is vzmg1b or vzmglb -- looks more like vzmglb to me.
dpb
dpb 2024년 7월 30일
편집: dpb 2024년 7월 30일
Yeah, I forget about the limited number of file extensions that Mathworks has identified as text....I figure it ought to try anything that isn't known to be something else, but there are so many arcane naming conventions, I guess it's tough. But, .prn is pretty common...

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

답변 (1개)

dpb
dpb 2024년 7월 30일
편집: dpb 2024년 7월 30일
More generically, but the same idea
ROOT='C:\Users\vzmglb\Desktop\29july2024'; % set a root for the data files
d=dir(fullfile(ROOT,'*.prn')); % return all .prn files; adapt wildcard to suit
for i=1:numel(d); % iterate over all files found
fqn=fullfile(d.folder,d.name); % build fully-qualified filename
data=readcell(fqn,'filetype','text'); % read the .prn file
fqn=strrep(fqn,'.prn','.xlsx'); % convert the filename to match new format/type
writecell(data,fqn)
end
The above will put a set of files in the same root folder/directory with the base name the same as the original but with the correct .xlsx extension. You could define a different output folder and build the filename similarly as done above for the input if desired.
  댓글 수: 1
dpb
dpb 2024년 8월 1일
편집: dpb 2024년 8월 3일 13:29
You did not run the code given which is
data=readcell(fqn,'filetype','text'); % read the .prn file
Use the result from the call to dir() with the fully-qualified filename; don't hard code in a name; that defeats the whole purpose of generalizing the code.
In particular, you gave only a file name without the location which isn't where you're running the MATLAB code from so the file isn't found.
If you want a particular file set, as noted before, modify the wildcard matching pattern to return those of interest or further generalize/adapt the basic code to pass a particular name or add in a call to uigetfile to let you use a dialog to select files.
ADDENDUM
"...don't hard code in a name..."
And certainly there's no point in hard-coding a specific file name inside a loop; if it worked by adding the fully-qualified name that would simply read the same file however many times the loop ran; hardly a useful thing...

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

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by