필터 지우기
필터 지우기

Insert 2 cell arrays in txt data

조회 수: 1 (최근 30일)
cemsi888
cemsi888 2017년 3월 20일
댓글: Renato Agurto 2017년 3월 21일
Hi I have a really easy question. I have one cell Array which consists of 2 cells. I would like to write These two cells in txt data. Actually i can now write both cells in txt however i would like put tab between both two cell elements. Although I added \t. Matlab does not put tab both elements. Could u please help me.Here is my code.
formatSpec='%s\t\n'
for ii=1:length(combined_data(:,1))
com1=char(combined_data{ii,1}{1,1});
com2=char(combined_data{ii,2}{1,1});
fprintf(fid ,formatSpec, [com1,com2]);
thanx a lot
end
fclose(fid);;

채택된 답변

Renato Agurto
Renato Agurto 2017년 3월 20일
I think you need two %s separated by the tab:
formatSpec='%s\t%s\n'
and:
fprintf(fid ,formatSpec, com1, com2); %without brackets
  댓글 수: 2
cemsi888
cemsi888 2017년 3월 20일
Thanx a lot Renato. Could u please explain me why we did not Need to use brackets? Thanx a lot
Renato Agurto
Renato Agurto 2017년 3월 21일
with brackets you join the 2 chars into one char. Without brackets you assign every char (com1 & com2) to the respective '%s' in your string.
I hope this helps you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by