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:
save data in a .txt file, fprintf function

Subject: save data in a .txt file, fprintf function

From: Giorgia

Date: 27 Sep, 2012 13:29:08

Message: 1 of 4

Hi all,
I'm having some problem in setting the option for the function fprintf in order to have the data saved with a specific structure.
I have to use SVM classifier at the end so I want my data to be structured like this

1 1: 56.23
1 1: 55.12
0 1: 9.88

where in each line there's one of my feature vector. I'd like to creat a loop that each time adds a new line to the .txt file.

I'm not able to find the correct setting of the function fprintf in order to have the data structured as above.


thank you all

Subject: save data in a .txt file, fprintf function

From: dpb

Date: 27 Sep, 2012 13:59:13

Message: 2 of 4

On 9/27/2012 8:29 AM, Giorgia wrote:
> Hi all,
> I'm having some problem in setting the option for the function fprintf
> in order to have the data saved with a specific structure.
> I have to use SVM classifier at the end so I want my data to be
> structured like this
>
> 1 1: 56.23
> 1 1: 55.12
> 0 1: 9.88
>
> where in each line there's one of my feature vector. I'd like to creat a
> loop that each time adds a new line to the .txt file.
>
> I'm not able to find the correct setting of the function fprintf in
> order to have the data structured as above.
...

Is the data array available all at once or generated a record at a time?
  How to write it depends on how it is stored and available...

As for a format, sotoo

fmt=['%d %d: %6.2f\n'];

would work to output the values as given above.

 >> i1=1;i2=i1;v=56.23;
 >> fmt=['%d %d: %6.2f\n'];
 >> fprintf(fmt,i1,i2,v)
1 1: 56.23
 >>

Salt to suit...

--

Subject: save data in a .txt file, fprintf function

From: Giorgia

Date: 27 Sep, 2012 14:49:06

Message: 3 of 4

it works, thank you a lot!!

another question, how can I do to save a feature per each line and not one right after the other?

this is the code I create

clss = [0 1 2];
a = 0.5:0.5:5;
data = fopen('prove.txt','w');
for j=1:3
    b = a*j;
    for i =1: length(a)
        fprintf(data,'%d %d:%6f\n',clss(j),i,b(i))
    end
end

I thougth \n was enough to create a new line but is not. Any suggestion?


thankyou

dpb <none@non.net> wrote in message <k41m3m$81g$1@speranza.aioe.org>...
> On 9/27/2012 8:29 AM, Giorgia wrote:
> > Hi all,
> > I'm having some problem in setting the option for the function fprintf
> > in order to have the data saved with a specific structure.
> > I have to use SVM classifier at the end so I want my data to be
> > structured like this
> >
> > 1 1: 56.23
> > 1 1: 55.12
> > 0 1: 9.88
> >
> > where in each line there's one of my feature vector. I'd like to creat a
> > loop that each time adds a new line to the .txt file.
> >
> > I'm not able to find the correct setting of the function fprintf in
> > order to have the data structured as above.
> ...
>
> Is the data array available all at once or generated a record at a time?
> How to write it depends on how it is stored and available...
>
> As for a format, sotoo
>
> fmt=['%d %d: %6.2f\n'];
>
> would work to output the values as given above.
>
> >> i1=1;i2=i1;v=56.23;
> >> fmt=['%d %d: %6.2f\n'];
> >> fprintf(fmt,i1,i2,v)
> 1 1: 56.23
> >>
>
> Salt to suit...
>
> --

Subject: save data in a .txt file, fprintf function

From: Giorgia

Date: 27 Sep, 2012 15:22:07

Message: 4 of 4

problem solved, i was mislead by the notepad visualisation.

thnks anyway


"Giorgia " <emika@hotmail.it> wrote in message <k41p12$3o5$1@newscl01ah.mathworks.com>...
> it works, thank you a lot!!
>
> another question, how can I do to save a feature per each line and not one right after the other?
>
> this is the code I create
>
> clss = [0 1 2];
> a = 0.5:0.5:5;
> data = fopen('prove.txt','w');
> for j=1:3
> b = a*j;
> for i =1: length(a)
> fprintf(data,'%d %d:%6f\n',clss(j),i,b(i))
> end
> end
>
> I thougth \n was enough to create a new line but is not. Any suggestion?
>
>
> thankyou
>
> dpb <none@non.net> wrote in message <k41m3m$81g$1@speranza.aioe.org>...
> > On 9/27/2012 8:29 AM, Giorgia wrote:
> > > Hi all,
> > > I'm having some problem in setting the option for the function fprintf
> > > in order to have the data saved with a specific structure.
> > > I have to use SVM classifier at the end so I want my data to be
> > > structured like this
> > >
> > > 1 1: 56.23
> > > 1 1: 55.12
> > > 0 1: 9.88
> > >
> > > where in each line there's one of my feature vector. I'd like to creat a
> > > loop that each time adds a new line to the .txt file.
> > >
> > > I'm not able to find the correct setting of the function fprintf in
> > > order to have the data structured as above.
> > ...
> >
> > Is the data array available all at once or generated a record at a time?
> > How to write it depends on how it is stored and available...
> >
> > As for a format, sotoo
> >
> > fmt=['%d %d: %6.2f\n'];
> >
> > would work to output the values as given above.
> >
> > >> i1=1;i2=i1;v=56.23;
> > >> fmt=['%d %d: %6.2f\n'];
> > >> fprintf(fmt,i1,i2,v)
> > 1 1: 56.23
> > >>
> >
> > Salt to suit...
> >
> > --

Tags for this Thread

No tags are associated with 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