How to write horizontally

4 ビュー (過去 30 日間)
Mekala balaji
Mekala balaji 2020 年 1 月 12 日
回答済み: Walter Roberson 2020 年 1 月 12 日
Hi,
I want to write 'x' and 'y' data side by side in each loop.
I sue below code
x=-5:1:5
y=x.^2
fid=fopen('test.txt','w')
for i = 1:lenth(x)
fprintf(fid,'%d\t\%d', (x(i) y(i))
end
fclose(fid)mat
but I am stillnot getting it.
desired outpit:
X -5 -4 -3 -2 -1 0 1 2 3 4 5
Y 25 16 9 4 1 0 1 4 9 16 25

採用された回答

Walter Roberson
Walter Roberson 2020 年 1 月 12 日
fid = fopen('TheFileName.txt','wt');
fprint(fid, 'x') ;
fprintf(fid, '%6g',x);
fprintf(fid, '\n') ;
Then same for y. Then
fclose(fid) ;

その他の回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 1 月 12 日
編集済み: KALYAN ACHARJYA 2020 年 1 月 12 日
x=-5:1:5;
y=x.^2;
disp('desired output:');
x
y
More
x=-5:1:5;
y=x.^2;
disp('desired outpit');
fprintf('x');
disp(x);
fprintf('y');
disp(y);
Result:
desired outpit
x -5 -4 -3 -2 -1 0 1 2 3 4 5
y 25 16 9 4 1 0 1 4 9 16 25
  4 件のコメント
Mekala balaji
Mekala balaji 2020 年 1 月 12 日
x=-5:1:5;
y=x.^2;
disp('desired outpit');
fprintf('x');
disp(x);
fprintf('y');
disp(y);
but, how to write this to file,
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 1 月 12 日

サインインしてコメントする。

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by