필터 지우기
필터 지우기

How to combine cells with a matrix?

조회 수: 1 (최근 30일)
rui gao
rui gao 2019년 1월 30일
댓글: rui gao 2019년 1월 31일
I want to extract 6 lines from a ascii file, and add these lines into another text file which just contains a matrix, like 500*500.
Now, I extract the first 6 lines from the ascii file:
%% extract title for the new ascii file
fid = fopen('filename','r')
numLines = 6; % I knew there are 6 lines I need
title = cell(numLines,1);
for ii = 1:numLines
title(ii) = {fgetl(fid)};
end
fclose(fid);
Q1: how to combine these lines with another matrix to generate a new text file?
Q2: how to output this new text file?
Any help would be appreciated.

채택된 답변

KSSV
KSSV 2019년 1월 30일
Read about fprintf and dlmwrite. First write the text lines and then write the matrix.
  댓글 수: 2
rui gao
rui gao 2019년 1월 30일
Could you please comment more on this question, I do appreciate it.
The title should be like this:
WeChat Image_20190130125719.png
and honestly, this text file contains a matrix, which is a 5000*5000. (So, one of my thought is whether I can replace this 5000*5000 matrix only by another 5000*5000 matrix, and then output this new hybrid text?)
Another text file just contains a 5000*5000 matrix.
rui gao
rui gao 2019년 1월 31일
Yeah, it seems that what you (KSSV) said is the only way to address the problem.
Now, the problem has been solved by your thought.
Thanks again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by