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

New to MATLAB?

proper orientation & writing to text file

Asked by shaz

shaz

on 23 Nov 2012
Accepted Answer by Walter Roberson

Walter Roberson

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

shaz

shaz

Tags

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson

Walter Roberson

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

4 Comments

Walter Roberson

Walter Roberson

on 23 Nov 2012

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

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?

Walter Roberson

Walter Roberson

on 27 Nov 2012

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

Walter Roberson

Walter Roberson

Contact us