From: Naftali Herscovici on
Hello,

I need to print a combination of variables

a{1}='010101010';
a{2}='011101010';
a{3}='110101010';
b(1)=3.25;
b(2)=-3.4;
b(3)=1.25;
I would like to use something similar to
fprintf('%s %f5.2\n',a,b);

Apparently it does not work. I understand that fprintf is not defined for 'cell' variables, but I could not find a print format that supports both strings/cells and numbers.

Any suggestions?

Thanks
From: sscnekro on
Hi Naftali Herscovici,

> I would like to use something similar to
> fprintf('%s %f5.2\n',a,b);

I don't know anything on fprintf, but look - I copied precisely your variables to workspace. If you refer to a and b as a whole, you get "??? Error using ==> fprintf
Function is not defined for 'cell' inputs."

.... however, if you refer to single elements in a and b, you get:
d = fprintf('%s %f5.2\n',a{1}, b(1));
010101010 3.2000005.2

Is this what you wanted? To combine a{i} with b(i)? I don't quite see whether 3.2000005.2 really is what you wanted to get out of b... By the way, ML Experts have been murmuring about low traffic on the newsgroup last days, so I hope you will soon get a better assistance than mine. Good luck.
From: ImageAnalyst on
Do it this way instead, and it will work:

for k = 1 : length(a)
fprintf(1, '%s %5.2f\n',a{k},b(k));
end
From: us on
"Naftali Herscovici" <tuli01(a)hotmail.com> wrote in message <hu0gkg$jgc$1(a)fred.mathworks.com>...
> Hello,
>
> I need to print a combination of variables
>
> a{1}='010101010';
> a{2}='011101010';
> a{3}='110101010';
> b(1)=3.25;
> b(2)=-3.4;
> b(3)=1.25;
> I would like to use something similar to
> fprintf('%s %f5.2\n',a,b);
>
> Apparently it does not work. I understand that fprintf is not defined for 'cell' variables, but I could not find a print format that supports both strings/cells and numbers.
>
> Any suggestions?
>
> Thanks

a hint:
- this FEX submission does what you want...

http://www.mathworks.com/matlabcentral/fileexchange/23840

us
From: ImageAnalyst on
On May 31, 5:24 pm, ImageAnalyst <imageanal...(a)mailinator.com> wrote:
> Do it this way instead, and it will work:
>
> for k = 1 : length(a)
>     fprintf(1, '%s %5.2f\n',a{k},b(k));
> end

--------------------
Or, alternatively:
fprintf(1, '%s %5.2f\n',a{:},b(:));

Note that a and b need to be the same length for you to do it in a
single fprintf() statement, otherwise one will "run out" before the
other and you won't get the expected results.