MATLAB Answers

shaz
0

proper orientation & writing to text file

Asked by shaz
on 23 Nov 2012

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

  0 Comments

Tags

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 23 Nov 2012
 Accepted answer

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

  4 Comments

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 Simon
on 27 Nov 2012

@Walter: It seems like your comments have lost their context. Did somebody delete some other comments? If so, who and why?

Looks like all of shaz's comments are gone :(


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!