Thread Subject: matlab fwrite error

Subject: matlab fwrite error

From: pietro

Date: 3 Jan, 2009 21:19:01

Message: 1 of 5

i have created that function, but matlab gives me the following error

[B]??? Error using ==> fwrite
Invalid precision.[/b]

when i called the fwrite. How could i resolve this problem?



[code]function vibrazioni_2631 (dati,nome,area_prova,cond_prova,vel)
kx=1.4;
ky=1.4;
kz=1;
dt=dati(4,1)-dati(3,1);
l=length(dati(1,:))
f_nome=[nome, '_elab.txt'];
fid=fopen(f_nome, 'a')

prova.nome=nome;
prova.area=area_prova;
prova.cond=cond_prova;
prova.vel=vel;
%calcolo rms
prova.aw_x=sqrt(dt*trapz(dati(:,2).^2)/(dati(end,1)));
prova.aw_y=sqrt(dt*trapz(dati(:,4).^2)/(dati(end,1)));
prova.aw_z=sqrt(dt*trapz(dati(:,6).^2)/(dati(end,1)));

prova

%calcolo accelerazione risultante
prova.aw=max([kx.*prova.aw_x,ky.*prova.aw_y,kz.*prova.aw_z]);

%calcolo crest factor
prova.cf_x=max(dati(:,2))/prova.aw_x;
prova.cf_y=max(dati(:,4))/prova.aw_y;
prova.cf_z=max(dati(:,6))/prova.aw_z;

%calcolo vdv
prova.vdv_x=(dt*trapz(dati(:,2).^4))^0.25;
prova.vdv_y=(dt*trapz(dati(:,4).^4))^0.25;
prova.vdv_z=(dt*trapz(dati(:,6).^4))^0.25;
prova.vdv=max([kx.*prova.vdv_x,ky.*prova.vdv_y,kz.*prova.vdv_z]);


%calcolo tempo
prova.ore=fix((0.5/prova.aw).^2*8)
prova.min=rem((0.5/prova.aw).^2*8,60)
prova.tempo=(0.5/prova.aw).^2*8/24
if prova.tempo>=1
    prova.tempo=0.99
end


fwrite (fid, '%s ; %s ; %s ; %4.0f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f ; %4.2f', ...
prova.nome, prova.cond, prova.area,prova.vel,prova.aw,prova.vdv,prova.ore,prova.min,prova.aw_x,prova.aw_y,prova.aw_z,prova.vdv_x,prova.vdv_y,prova.vdv_z,...
prova.cf_x,prova.cf_y ,prova.cf_z ,prova.tempo);

fclose (fid)
[/code]

Subject: matlab fwrite error

From: Rune Allnor

Date: 3 Jan, 2009 21:58:14

Message: 2 of 5

On 3 Jan, 22:19, "pietro " <bracard...@email.it> wrote:
> i have created that function, but matlab gives me the following error
>
> [B]??? Error using ==> fwrite
> Invalid precision.[/b]
>
> when i called the fwrite. How could i resolve this problem?
...
> fwrite (fid, '%s ; %s ; %s ; %4.0f ;

Try FPRINTF instead of FWRITE.

Rune

Subject: matlab fwrite error

From: pietro

Date: 3 Jan, 2009 22:21:02

Message: 3 of 5

Rune Allnor <allnor@tele.ntnu.no> wrote in message <f78f3ad5-b36d-4038-b077-ca822f90563f@v39g2000pro.googlegroups.com>...
> On 3 Jan, 22:19, "pietro " <bracard...@email.it> wrote:
> > i have created that function, but matlab gives me the following error
> >
> > [B]??? Error using ==> fwrite
> > Invalid precision.[/b]
> >
> > when i called the fwrite. How could i resolve this problem?
> ...
> > fwrite (fid, '%s ; %s ; %s ; %4.0f ;
>
> Try FPRINTF instead of FWRITE.
>
> Rune

thank you, now it works. Could you explain me, why it doesn't work with fwrite?

Subject: matlab fwrite error

From: Brian Borchers

Date: 3 Jan, 2009 22:43:53

Message: 4 of 5

On Jan 3, 3:21 pm, "pietro " <bracard...@email.it> wrote:
>Thank you, now it works. Could you explain me, why it doesn't work with fwrite?

The fwrite function writes raw binary data- it doesn't accept a format
string like frpintf does. help fwrite will give you an explanation of
what fwrite does.

Subject: matlab fwrite error

From: pietro

Date: 3 Jan, 2009 23:56:01

Message: 5 of 5

Brian Borchers <borchers.brian@gmail.com> wrote in message <f2ae7979-312c-4be5-95d7-d4d528289ead@w1g2000prk.googlegroups.com>...
> On Jan 3, 3:21 pm, "pietro " <bracard...@email.it> wrote:
> >Thank you, now it works. Could you explain me, why it doesn't work with fwrite?
>
> The fwrite function writes raw binary data- it doesn't accept a format
> string like frpintf does. help fwrite will give you an explanation of
> what fwrite does.

ok thank you. :)

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com