필터 지우기
필터 지우기

fprinf format

조회 수: 1 (최근 30일)
Win Thomas Halim
Win Thomas Halim 2011년 5월 9일
hi, i have this problem, suppose i have
x=[1,2,3]
y=[4,5,6]
z=[7,8,9]
i had it save use "fid=fopen" and "fprintf" command to "results.str", how to make the results.str saved in this following format:
s
100
1
7 1 4
8 2 5
9 3 6
which "s" 100 and 1 is a constant value to begin with, followed by z in the first column, then x and y.
anyone can help?

채택된 답변

Paulo Silva
Paulo Silva 2011년 5월 9일
x=[1,2,3]
y=[4,5,6]
z=[7,8,9]
FileName='results';
FID = fopen(FileName, 'w');
if FID < 0, error('Cannot open file'); end
data = [z', x', y'];
fprintf(FID, 's\n%g\n%g\n', 100,1);
fprintf(FID, '%g %g %g\n', data');
fclose(FID);
  댓글 수: 2
Win Thomas Halim
Win Thomas Halim 2011년 5월 9일
thank you very much!
Win Thomas Halim
Win Thomas Halim 2011년 5월 9일
ive just try your code, turns out results.str become :
s 100 1 z x y.
is it possible to made 100 is just below s, 1 is below 100 and z x y are below 1?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by