From: Mike on
Hi

I use textscan to read the file. Then I want to fprintf to screen.
But fails.

[A, count] = textscan(fid,'%s %d %d %d %f %f %f %d %d %d %f %f %f %f
%f %f %f %f %f %d %d %d')
fprintf('%s\n',A{1,:})

it shows

A =

Columns 1 through 6

{140x1 cell} [140x1 int32] [140x1 int32] [140x1 int32]
[140x1 double] [140x1 double]
......

??? Error using ==> fprintf
Function is not defined for 'cell' inputs.

>> whos A
Name Size Bytes Class Attributes

A 1x22 30440 cell


I don't understand why column 1 has {140x1 cell} but A has size 1x22
cell?
how to show colunn 1 cell?

Mike
From: TideMan on
On Mar 11, 4:28 pm, Mike <sulfate...(a)gmail.com> wrote:
> Hi
>
> I use textscan to read the file.  Then I want to fprintf to screen.
> But fails.
>
> [A, count] = textscan(fid,'%s %d %d %d %f %f %f %d %d %d %f %f %f %f
> %f %f %f %f %f %d %d %d')
> fprintf('%s\n',A{1,:})
>
> it shows
>
> A =
>
>   Columns 1 through 6
>
>     {140x1 cell}    [140x1 int32]    [140x1 int32]    [140x1 int32]
> [140x1 double]    [140x1 double]
> .....
>
> ??? Error using ==> fprintf
> Function is not defined for 'cell' inputs.
>
> >> whos A
>
>   Name      Size            Bytes  Class    Attributes
>
>   A         1x22            30440  cell
>
> I don't understand why column 1 has {140x1 cell} but A has size 1x22
> cell?
> how to show colunn 1 cell?
>
> Mike

But why on earth are you using fprintf?
fprintf prints to a file!
Look at the first line when you type help fprintf:
FPRINTF Write formatted data to file.

All you need to do is this:
A1=A{1}; % Note the curly brackets
Now, A1 is a cell array containing strings.
Similarly,
A2=A{2};
gives a column vector A2 of integers.
etc
etc
From: Walter Roberson on
TideMan wrote:
> On Mar 11, 4:28 pm, Mike <sulfate...(a)gmail.com> wrote:

>> fprintf('%s\n',A{1,:})

> But why on earth are you using fprintf?
> fprintf prints to a file!
> Look at the first line when you type help fprintf:
> FPRINTF Write formatted data to file.

Yup. Unless, that is, you read further in the help, and see that if you
omit the fid from fprintf, that the effect is as if you had specified
fid 1, which is defined as printing to standard output (e.g., the
command window.)

As to why you would do that rather than use sprintf() and no semi-colon
after the sprintf(): perhaps to avoid 'ans=', or perhaps to capture the
count of items processed that is returned by fprintf() .
From: Mike on
On Mar 11, 12:17 pm, Walter Roberson <rober...(a)hushmail.com> wrote:
> TideMan wrote:
> > On Mar 11, 4:28 pm, Mike <sulfate...(a)gmail.com> wrote:
> >> fprintf('%s\n',A{1,:})
> > But why on earth are you using fprintf?
> > fprintf prints to a file!
> > Look at the first line when you type help fprintf:
> > FPRINTF Write formatted data to file.
>
> Yup. Unless, that is, you read further in the help, and see that if you
> omit the fid from fprintf, that the effect is as if you had specified
> fid 1, which is defined as printing to standard output (e.g., the
> command window.)
>
> As to why you would do that rather than use sprintf() and no semi-colon
> after the sprintf(): perhaps to avoid 'ans=', or perhaps to capture the
> count of items processed that is returned by fprintf() .

thank you very much.

Mike
 | 
Pages: 1
Prev: SVM simple question
Next: SELF ORGANIZED MAP