proper orientation & writing to text file

i have a string like
sample1 = ['Software','UserName','Author'];
sample2 = ['Matlab','john','Author1'];
sample3 = ['c','wright','Author2'];
now i need to write to txt file in below format
sample output format
Software UserName Author
Matlab john Author1
c wright Author2
problem is not able to adjust whitespaces

 採用された回答

Walter Roberson
Walter Roberson 2012 年 11 月 23 日

0 投票

sample1 = {'Software','UserName','Author'}; %NOT square brackets!
fprintf('%14s %-14s %14s\n', sample1{:});

4 件のコメント

Walter Roberson
Walter Roberson 2012 年 11 月 23 日
Have you considered the possibility that it is not the {} that is the issue, and that instead the issue is that the above fprintf() command does not specify which text file to write to?
The code is intended to be sample code to allow you to examine the behavior and refine for yourself what precise format you want to use. After you have worked that out, adjust the fprintf() to reflect the file identity you want to write into.
Walter Roberson
Walter Roberson 2012 年 11 月 23 日
The problem is not with the {} !!
sample1 = {'Software','UserName','Author'}; %NOT square brackets!
fid = fopen('YourOutput.txt', 'wt');
fprintf(fid, '%14s %-14s %14s\n', sample1{:}); %notice first argument!
fclose(fid);
Jan
Jan 2012 年 11 月 27 日
@Walter: It seems like your comments have lost their context. Did somebody delete some other comments? If so, who and why?
Walter Roberson
Walter Roberson 2012 年 11 月 27 日
Looks like all of shaz's comments are gone :(

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by