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

Thread Subject:
fprintf['text' vector 'text' vector]???

Subject: fprintf['text' vector 'text' vector]???

From: Sören Sieberling

Date: 1 Jul, 2010 14:46:07

Message: 1 of 3

Hello,

Could someone tell me how I can print this using fprintf, I probably missed an insturction somewhere:

DE = [ 0.5000 0.7000 0.9000; 2.0000 3.0000 4.0000 ]; > CHECK)

With A = 0.5 0.7 0.9 and B 2 3 4

using fprintf in one line. Right now this is what I do:

fid = fopen ('test.txt', 'w');

fprintf(fid,'DE = [ ')
fprintf(fid,'%6.4f',A)
fprintf(fid,'; ')
fprintf(fid,'%6.4f',B)
fprintf(fid,' ]; > CHECK)')

fclose(fid);

Seems kind of exaggerated. I was hoping to end up with something like:

fid = fopen ('test.param', 'w');
fprintf(fid,'DE = [ % 6.4f ; % 6.4f ] > lookupTable_BUS)' , A, B)
fclose(fid);

But this doesn't work.

Thanks,
Soeren

Subject: fprintf['text' vector 'text' vector]???

From: Sean

Date: 1 Jul, 2010 15:01:21

Message: 2 of 3

"Sören Sieberling" <seuren83@hotmail.com> wrote in message <i0i9nf$hnj$1@fred.mathworks.com>...
> Hello,
>
> Could someone tell me how I can print this using fprintf, I probably missed an insturction somewhere:
>
> DE = [ 0.5000 0.7000 0.9000; 2.0000 3.0000 4.0000 ]; > CHECK)
>
> With A = 0.5 0.7 0.9 and B 2 3 4
>
> using fprintf in one line. Right now this is what I do:
>
> fid = fopen ('test.txt', 'w');
>
> fprintf(fid,'DE = [ ')
> fprintf(fid,'%6.4f',A)
> fprintf(fid,'; ')
> fprintf(fid,'%6.4f',B)
> fprintf(fid,' ]; > CHECK)')
>
> fclose(fid);



%DE = [ 0.5000 0.7000 0.9000; 2.0000 3.0000 4.0000 ]; > CHECK)

A = [0.5, 0.7, 0.9];
B = [2, 3, 4];

fid = fopen('test4Soren.txt', 'w');

fprintf(fid,['DE = [' sprintf(' %6.4f',A) ';' sprintf(' %6.4f',B) ']; > CHECK)'])

fclose(fid);

Subject: fprintf['text' vector 'text' vector]???

From: Sören Sieberling

Date: 1 Jul, 2010 16:07:04

Message: 3 of 3

Hey Sean,

Thanks.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us