# HELP IN FILES IN MATLAB

Page 1 of 1

## 5 Replies - 969 Views - Last Post: 06 June 2011 - 08:14 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=227222&amp;s=ca390d95f75a7952cdb0702e45930465&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 javagoutom

Reputation: 0
• Posts: 114
• Joined: 20-September 07

# HELP IN FILES IN MATLAB

Posted 11 April 2011 - 11:22 PM

I AM A FRESH LEARNER OF MATLAB AND TRYING TO GET ALONG WITH FILES.MY PROBLEMS LIES IN THAT THE FILE IS CREATED IN CURRENT DIRECTORY BUT WHEN I OPEN THE FILE AFTER EXECUTION OF PROGRAM IT SHOWS NO DATA.ANY HELP WILL BE APPRECIATED.

FOLLOWING IS A SIMPLE PROGRAM I WAS TRYING!
```
fid=fopen('data.m','w');
a=input('\nvalue of a: ')
b=input('\nvalue of b: ')
c=a+b;
d=a*b;
fprintf('\nvalue of c=%f \n',c)
fprintf('\nvalue of d=%f \n',d)
fclose(fid);

```

Is This A Good Question/Topic? 0

## Replies To: HELP IN FILES IN MATLAB

### #2 nandureddy

Reputation: 28
• Posts: 129
• Joined: 31-January 11

## Re: HELP IN FILES IN MATLAB

Posted 11 April 2011 - 11:47 PM

This should work.
```a=input('\nvalue of a: ')
b=input('\nvalue of b: ')
c=a+b;
d=a*b;
fid=fopen('data.m','w')
fprintf(fid, 'value of\n  c = %f',c)
fprintf(fid, 'value of\n  d= %f',d)
fclose(fid)
```

### #3 javagoutom

Reputation: 0
• Posts: 114
• Joined: 20-September 07

## Re: HELP IN FILES IN MATLAB

Posted 12 April 2011 - 01:25 AM

THANKS FOR YOUR REPLY.YES!IT HAS WORKED AND I AM SENDING YOU THE OUTPUT THAT I HAVE GOT IN COMMANDwindow.CAN YOU TELL ME,WHAT VALUE DOES "FID" GET AND WHAT THE LAST ANS=O MEANS?

```value of a: 2

a =

2

value of b: 3

b =

3

fid =

3

ans =

23

ans =

22

ans =

0

```

### #4 javagoutom

Reputation: 0
• Posts: 114
• Joined: 20-September 07

## Re: HELP IN FILES IN MATLAB

Posted 12 April 2011 - 01:34 AM

I AM USING MATLAB IN MY PROJECT WORK TOO.THERE I HAVE TO TAKE INPUTS AND GIVE OUTPUT AND WHICH I HAVE TO DO WITHIN FILE.SO,THEN SHALL I USE 'r' MODE.

I AM SENDING THE PART OF MY PROGRAM.
```
fid= fopen('data.m','w');
%input parameters
PCR=264.0;TCR=1184.9;VCR=0.0669;ZCR=0.237;TB=881.0;B00=1.6368;B01=-1.9693;B02=2.4638;B03=-1.5841;B10=-0.04615;B11=0.21874;B12=-0.36461;B13=0.25136;
A=0.84167;
B=-1.4704;
C=1.67165;
D=-0.59198;
AA=0.03826;
BB=0.00747;
CC=0.041126;
DD=-0.01395;

%function call

%PV; RPM;X;RDROPNSm; SMD;UINJ; TEMPC;VDR0P;VDR0PNS;TDROPNSc;DROMNSgr;DMASS;TDROPC;DRO;radius;data;DPRES;DINJ;TEMP;PRES;VOL;TDROP;AIRVEL;AM ;HV;DENSL;SURT;VISCL;CPL;CONDA;VISCA;CPA;RGAS;DENSA;GASMASS;VAPMASS;VDROP;RDROP;DROMO;DROMNS;PC;RELVEL;VDROPNS;RDROPNS;
%TDROPNS;PERCENT;D12;MWA;MWF;DT;REYN;SC;PR;REYN12;REYN23;SC13;PR13;Y;YSUR;BY;BYB;SHER;NUSS;AAR;AAS;AAT;AAV;RDROP3;RDROPNS3;CD;DROM;AAW;RDROPA;

B20=2.1138e-3;
B21=-8.0028e-3;
B22=12.8763e-3;
B23=-11.3805e-3;
B30=0.7845e-5;
B31=-8.2328e-5;
B32=14.8059e-5;
B33=9.5672e-5;
B40=0.6923e-6;
B41=5.2604e-6;
B42=8.6895e-6;
B43=-2.1812e-6;
disp(B20)

format long g;
%program testing
RPM=input('\nENTER RPM ');
X=input('\nENTER X ');
DPRES=input('\nENTER PR DIFF  DPRES ');
DINJ=input('\nINJECTION DIA  DINJ ');
TEMP=input('\nENTER TEMP  TEMP ');
PRES=input('\nENTER PR   PRES');
VOL=input('\nENTER VOL  VOL ');
TDROP=input('\nENTER DROPLET TEMP   TDROP ');
AIRVEL=input('\nENTER AIR VEL   AIRVEL');
TEMPC =TDROP-273.15;
fprintf('\nTEMP IN CELCIUS = %4.6f',TEMPC);

%calling functions
[HV]=LHVAP(TEMPC);
fprintf('\nLHVAP=%f\n',HV);

[PV]=VAPRES(TEMPC);
fprintf('\nVAPRESS=%f\n',PV);

[DENSL]=DENSLIQ(TEMPC,PRES);
fprintf('\nDENSL=%f\n',DENSL);

[SURT]=SURTEN(TEMPC);
fprintf('\nSURT=%f\n',SURT);

[VISCL]=DVISC(TEMPC,PRES);
fprintf('\nVISCL=%f\n',VISCL);

CPL=CPLIQ(TEMPC);
fprintf('\nCPL=%f\n',CPL);

TEMPC = (TEMP+2.0*TDROP)/3-273.15;

%calling functions

[CONDA]=PROPAIR1(TEMPC);
fprintf('\nCONDA=%9.8f\n',CONDA);

[VISCA]=PROPAIR2(TEMPC);
fprintf('\nVISCAA=%9.8f\n',VISCA);

[CPA]=PROPAIR3(TEMPC);
fprintf('\nCPA=%9.8f\n',CPA);

RGAS = 8314.0/28.96;
DENSA = PRES/RGAS/TEMP;
PC = 3.14159;
disp(RGAS)
disp(DENSA)
disp(PC)

%-------------------------------------------------------------------
%-------CALCULATION OF THE DROPLET INITIAL CHARACTERISTICS----------
%-------------------------------------------------------------------
%calling functions

UINJ=INJECT1(DPRES,DINJ,SURT,DENSA,DENSL,VISCA,VISCL);
fprintf('\nUINJ=%9.8f\n',UINJ);
SMD=INJECT2(DPRES,DINJ,SURT,DENSA,DENSL,VISCA,VISCL);
fprintf('\nSMD=%9.8f\n',SMD);

%.............

GASMASS = DENSA*VOL;
fprintf('\nGASMASS=%9.8f',GASMASS);
VAPMASS =0.0;
VDROP =UINJ;
RDROP =SMD/2.0;
%RDROPA=4.0*PC*RDROP;
%format long e;
DROMO =4*PC*(RDROP^3.0)*DENSL/3.0;
RELVEL =abs(AIRVEL-VDROP);
fprintf('\nRDROP=%12.12f\t\t DROMO=%15.22f',GASMASS,DROMO);
fprintf('\nRELVEL=%9.8f',RELVEL);
%loop
%while(RDROPNS>0.0)

fprintf('\n*********************************');
fprintf('\nDROPLET INITIAL CHARACTERISTICS');
fprintf('\n*********************************');
data=(10^6);
DRO=DROMO*1000.0;
fprintf('\nMASS(gr)=%33.22f',DRO);
TDROPC=TDROP-273.15;
fprintf('\nTEMPERATURE(C)=%7.9f',TDROPC);
fprintf('\nVELOCITY(M/S)=%22.22f',VDROP);
PERCENT=0.00;
I=1;

while(RDROP>0.0)
%-------------------------------------------------------------------
%CALCULATION OF THE DROPLET EVAPORATION HISTORY------------
%-------------------------------------------------------------------
%call fuction EVAPOR

[DROMNS,TDROPNS,VAPMASS,VDROPNS,RDROPNS]=EVAPOR (RPM,RDROP,VDROP,DROMO,X,I,TDROP,GASMASS,VAPMASS,TEMP,PRES,VOL,AIRVEL,RELVEL,PC);
%.............

fprintf('\n*********************************');
fprintf('\nVELOCITY(M/S)=%f',VDROP);
fprintf('\nDROPLET CHARACTERISTICS AT THE END OF THE TIME STEP');
fprintf('\n*********************************');

%AM=pow(10,6);
%/RDROPNSm=RDROPNS*AM;
DROMNSgr=DROMNS*1000.0;
fprintf('\nMASS(gr)=%13.12f',DROMNSgr);
TDROPNSc=TDROPNS-273.15;
fprintf('\nTEMPERATURE(C)=%11.12f',TDROPNSc);
fprintf('\nVELOCITY(M/S)=%33.12f',VDROPNS);
fprintf('\n*********************************');
PERCENT=100*VAPMASS/DROMO;
fprintf('\nPERCENTAGE OF EVAPORATED MASS=%f',PERCENT);

fprintf('\nPERCENTAGE OF EVAPORATED MASS=%f\t\tSTEP=%f',PERCENT,I);

fprintf('\n*********************************');

RDROP=RDROPNS;
VDR0P=VDROPNS;
TDROP=TDROPNS;
RELVEL=VDROP-AIRVEL;
I=I+1;

end
nancy=input('give stay');
fclose(fid);

```

### #5 DrAcid

• New D.I.C Head

Reputation: 1
• Posts: 12
• Joined: 31-May 11

## Re: HELP IN FILES IN MATLAB

Posted 02 June 2011 - 10:39 AM

@javagoutom

FID stands for FileID and is usually an integer. I always have imagined it like a sort of a 'stream' or a 'channel'. If You open a file either for reading of for writing, it is done thru a 'stream' with a unique ID (==FID). You open a channel, you transfer data, you close a channel...

if You'd try help fclose in console, You would find out that this particular function returns 0 if closing a 'channel' with an ID of FID is successful, but it returns -1 if it's unsuccessful.

Also, FCLOSE('all') closes all open files, except 0, 1 and 2. I guess they are reserved.

### #6 mufasa

• New D.I.C Head

Reputation: 2
• Posts: 44
• Joined: 12-February 10

## Re: HELP IN FILES IN MATLAB

Posted 06 June 2011 - 08:14 AM

DrAcid, on 02 June 2011 - 12:39 PM, said:

Also, FCLOSE('all') closes all open files, except 0, 1 and 2. I guess they are reserved.

fids 0, 1, 2 refer to standard input, standard output and standard error (output) so MATLAB can't grant you permission to close them (probably - I don't know a ton about MATLAB).

This post has been edited by mufasa: 06 June 2011 - 08:15 AM