필터 지우기
필터 지우기

Converting a matrix of strings to a txt file

조회 수: 2 (최근 30일)
Paramonte
Paramonte 2020년 2월 21일
댓글: Paramonte 2020년 2월 21일
Hi there!
I have a mtarix of strings x_mtarix:
x_matrix =
5×3 string array
"A" "B" "C"
"AA" "BB" "CC"
"AAA" "BBB" " "
"AAAA" " " " "
"AAAAA" " " " "
which I would like to save in a text file that woul contain the x_matrix values keping the same appearance:
A B C
AA BB CC
AAA BBB
AAAA
AAAAA
I have used an assortment of variations of:
fid = fopen('output.txt','wt');
fprintf(fid,'%s\n',x_matrix);
fclose(fid);
But I dont quite get the results I want
Thanks in advance

채택된 답변

Stephen23
Stephen23 2020년 2월 21일
편집: Stephen23 2020년 2월 21일
  1. the format string need to have 3 conversion operators (or as many as you want on each line).
  2. the matrix needs to be tranposed.
For example:
fmt = repmat('%8s ',1,3);
fmt = [fmt(1:end-1),'\n'];
fprintf(fid, fmt, x_matrix.')
  댓글 수: 1
Paramonte
Paramonte 2020년 2월 21일
Thank you Stephen, it worked like a charm!!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by