f



error fopen('text.txt','w')

i am a beginner in Matlab guys, so i can't figure out what's wrong with my code. i need to open a text file and write data to it, but i got an error. here my simple code (sorry, my English is bad)

>> pwd

ans =

C:\Program Files\MATLAB\R2012a

>> fid=fopen('text.txt','w')

fid =

    -1


The text.txt doesn't exist.
0
Tunggul
11/2/2015 5:48:03 AM
comp.soft-sys.matlab 211266 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

6 Replies
692 Views

Similar Articles

[PageSpeed] 49

On 11/1/2015 11:48 PM, Tunggul Sagala wrote:
> i am a beginner in Matlab guys, so i can't figure out what's wrong with my code.
>i need to open a text file and write data to it, but i got an error. here my simple code (sorry, my English is bad)
>
>>> pwd
>
> ans =
>
> C:\Program Files\MATLAB\R2012a
>
>>> fid=fopen('text.txt','w')
>
> fid =
>
>      -1
>
>
> The text.txt doesn't exist.
>

First thing, is why are you trying to create a file in the same folder
where Matlab is installed? Have you checked permissions on that
folder? I am sure you'll find you can not create a file there as
normal user and must be admin.

Second, to create a file for writing if it does not exist, use
the 'a' option, not the 'w' option. See help on fopen.

You should not be playing around and creating files
in Matlab installation folder.

--Nasser

0
Nasser
11/2/2015 5:54:47 AM
On 11/1/2015 11:54 PM, Nasser M. Abbasi wrote:

> Second, to create a file for writing if it does not exist, use
> the 'a' option, not the 'w' option. See help on fopen.
>

That should be 'w+' not 'a'


0
Nasser
11/2/2015 5:56:25 AM
"Nasser M. Abbasi" wrote in message <n16tu8$eci$2@speranza.aioe.org>...
> On 11/1/2015 11:54 PM, Nasser M. Abbasi wrote:
> 
> > Second, to create a file for writing if it does not exist, use
> > the 'a' option, not the 'w' option. See help on fopen.
> >
> 
> That should be 'w+' not 'a'
> 

I have no special purpose to write data in to the Matlab installer folder. I am just trying that code and i got error. 
I've changed the 'w' to 'w+' and I it stills got error. 

how do i fix this? or how can i get permission access to the Matlab installer folder?
0
Tunggul
11/2/2015 10:19:03 AM
"Tunggul Sagala" <tunggul_sagala@yahoo.com> wrote in message <n17dan$pt0$1@newscl01ah.mathworks.com>...
> "Nasser M. Abbasi" wrote in message <n16tu8$eci$2@speranza.aioe.org>...
> > On 11/1/2015 11:54 PM, Nasser M. Abbasi wrote:
> > 
> > > Second, to create a file for writing if it does not exist, use
> > > the 'a' option, not the 'w' option. See help on fopen.
> > >
> > 
> > That should be 'w+' not 'a'
> > 
> 
> I have no special purpose to write data in to the Matlab installer folder. I am just trying that code and i got error. 
> I've changed the 'w' to 'w+' and I it stills got error. 
> 
> how do i fix this? or how can i get permission access to the Matlab installer folder?

No! Listen to what Nasser Abassi is telling you. If you look around this newsgroup, you will see that he is extremely knowledgeable and gives good advice.

If this isn't your personal computer and your individually licensed copy of Matlab, your organization may restrict access to the Matlab root folder (and other operating system and program folders). In any case, it's bad practice for anyone--especially a beginner--to be fooling around in the root folder of the program. If nothing else, you will clutter the folder with files that are not related to the basic functioning of the program, and at worst you could inadvertently overwrite or delete a program file or folder.

Create a different folder (work or data, for example) somewhere that you do have full read/write permission. Then try Nasser's suggestion. If you still get the same error, check to see if a file named text.txt is open elsewhere in another program.

Barry
0
Barry
11/2/2015 1:36:03 PM
"Barry Williams" <barry.r.williams@saic.com> wrote in message <n17os3$l1a$1@newscl01ah.mathworks.com>...
> "Tunggul Sagala" <tunggul_sagala@yahoo.com> wrote in message <n17dan$pt0$1@newscl01ah.mathworks.com>...
> > "Nasser M. Abbasi" wrote in message <n16tu8$eci$2@speranza.aioe.org>...
> > > On 11/1/2015 11:54 PM, Nasser M. Abbasi wrote:
> > > 
> > > > Second, to create a file for writing if it does not exist, use
> > > > the 'a' option, not the 'w' option. See help on fopen.
> > > >
> > > 
> > > That should be 'w+' not 'a'
> > > 
> > 
> > I have no special purpose to write data in to the Matlab installer folder. I am just trying that code and i got error. 
> > I've changed the 'w' to 'w+' and I it stills got error. 
> > 
> > how do i fix this? or how can i get permission access to the Matlab installer folder?
> 
> No! Listen to what Nasser Abassi is telling you. If you look around this newsgroup, you will see that he is extremely knowledgeable and gives good advice.
> 
> If this isn't your personal computer and your individually licensed copy of Matlab, your organization may restrict access to the Matlab root folder (and other operating system and program folders). In any case, it's bad practice for anyone--especially a beginner--to be fooling around in the root folder of the program. If nothing else, you will clutter the folder with files that are not related to the basic functioning of the program, and at worst you could inadvertently overwrite or delete a program file or folder.
> 
> Create a different folder (work or data, for example) somewhere that you do have full read/write permission. Then try Nasser's suggestion. If you still get the same error, check to see if a file named text.txt is open elsewhere in another program.
> 
> Barry


Thank you Barry. Sorry for asking a fool question in this group. a friend of mine (the man who introduced Matlab to me) said that Matlab have a special procedure in managing file, such as reading file, writing file, and saving file. According to his opinion, we can't writing a file in Matlab if its doesn't save in Matlab installer folder, if we do it will generate an error. I thought he was right, so when i got error in writing the 'text.txt file I thought it's because I can't write the file in the Matlab installer folder. But now, it's clear for me that his opinion is wrong . But once again, it's all my fault for asking it first before figure it out, and I feel sorry for. Thank you guys for your help, GBY.
0
Tunggul
11/2/2015 3:50:03 PM
"Tunggul Sagala" <tunggul_sagala@yahoo.com> wrote in message <n180nb$8e9$1@newscl01ah.mathworks.com>...
> "Barry Williams" <barry.r.williams@saic.com> wrote in message <n17os3$l1a$1@newscl01ah.mathworks.com>...
> > "Tunggul Sagala" <tunggul_sagala@yahoo.com> wrote in message <n17dan$pt0$1@newscl01ah.mathworks.com>...
> > > "Nasser M. Abbasi" wrote in message <n16tu8$eci$2@speranza.aioe.org>...
> > > > On 11/1/2015 11:54 PM, Nasser M. Abbasi wrote:
> > > > 
> > > > > Second, to create a file for writing if it does not exist, use
> > > > > the 'a' option, not the 'w' option. See help on fopen.
> > > > >
> > > > 
> > > > That should be 'w+' not 'a'
> > > > 
> > > 
> > > I have no special purpose to write data in to the Matlab installer folder. I am just trying that code and i got error. 
> > > I've changed the 'w' to 'w+' and I it stills got error. 
> > > 
> > > how do i fix this? or how can i get permission access to the Matlab installer folder?
> > 
> > No! Listen to what Nasser Abassi is telling you. If you look around this newsgroup, you will see that he is extremely knowledgeable and gives good advice.
> > 
> > If this isn't your personal computer and your individually licensed copy of Matlab, your organization may restrict access to the Matlab root folder (and other operating system and program folders). In any case, it's bad practice for anyone--especially a beginner--to be fooling around in the root folder of the program. If nothing else, you will clutter the folder with files that are not related to the basic functioning of the program, and at worst you could inadvertently overwrite or delete a program file or folder.
> > 
> > Create a different folder (work or data, for example) somewhere that you do have full read/write permission. Then try Nasser's suggestion. If you still get the same error, check to see if a file named text.txt is open elsewhere in another program.
> > 
> > Barry
> 
> 
> Thank you Barry. Sorry for asking a fool question in this group. a friend of mine (the man who introduced Matlab to me) said that Matlab have a special procedure in managing file, such as reading file, writing file, and saving file. According to his opinion, we can't writing a file in Matlab if its doesn't save in Matlab installer folder, if we do it will generate an error. I thought he was right, so when i got error in writing the 'text.txt file I thought it's because I can't write the file in the Matlab installer folder. But now, it's clear for me that his opinion is wrong . But once again, it's all my fault for asking it first before figure it out, and I feel sorry for. Thank you guys for your help, GBY.

Just wondering, Tunggul. Did you solve the problem you were having with fopen?
Barry
0
Barry
11/4/2015 11:30:02 AM
Reply:

Similar Artilces:

'is not' or '!='
A newbie question to you; what is the difference between statements like: if x is not None: and if x != None: Without any context, which one should be preferred? IMHO, the latter is more readable. On 2014-08-18 21:35, ElChino wrote: > A newbie question to you; what is the difference between statements > like: > if x is not None: > and > if x != None: > > Without any context, which one should be preferred? > IMHO, the latter is more readable. > "x == y" tells you whether x and y refer to objects that are equal. "x is y&qu...

'^=' and '~='?
Hello, What is the difference between '^=' and '~='? Thanks, Duckhye ...

error: expected '=', ',', ';', 'asm' or '__attrib
Hi I'm trying to compile an ADC Driver & come acrosss the following error. I've no experience writing drivers before, and hence have no clue how to fix it. Hope someone out there has encountered the problem & suggesst a fix for the same. The Error is I get is : qadc.c: At top level: qadc.c:97: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'qadc_read' make: *** [qadc.o] Error 1 [root@localhost qadc]# ########################################################################### ADC Driver Code ####################...

error: expected '=', ',', ';', 'asm' or '__attrib
Hi I'm trying to compile an ADC Driver & come acrosss the following error. I've no experience writing drivers before, and hence have no clue how to fix it. Hope someone out there has encountered the problem & suggesst a fix for the same. The Error is I get is : qadc.c: At top level: qadc.c:97: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'qadc_read' make: *** [qadc.o] Error 1 [root@localhost qadc]# ########################################################################### ADC Driver Code ##...

remove from a txt everything between '[' and '] ' (included '[' and '] ')
from: [FOOooOoOOO] this is ok1 [FOOooOOO] this is ok2 to: this is ok1 this is ok2 tnx! :) On Apr 3, 8:00 pm, slystoner <slysto...@gmail.com> wrote: > from: > [FOOooOoOOO] this is ok1 > [FOOooOOO] this is ok2 > > to: > this is ok1 > this is ok2 > > tnx! :) echo '[FOOooOoOOO]' | sed 's/\[[^]]\+\]//' Jeenu ha scritto: > On Apr 3, 8:00 pm, slystoner <slysto...@gmail.com> wrote: >> from: >> [FOOooOoOOO] this is ok1 >> [FOOooOOO] this is ok2 >> >> to: >> this is ok1 >> this is ok2 >> >...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal''''''''''''''
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; _____________________________________________________ SELECT "criteria" FROM "criteria" WHERE "criteria" UPDATE/APPEND "field selections" RecordSource "qryExample" = above text strings" _______________________________________________________________________ When i am running a SELECT query in this manner it works fine with no problems, and accepts the values of specified linked for...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal'''''''''''''' #2
Hi, Thanks for ur help there HJ. I know how to do the tasks you specified there. I would like for the update query to use field values from some of the fields on the form (frmInvoices) such as InvoiceNumber, DateFrom, DateTo. My problem is that an append/update query can't find the values in the open Form (frmInvoices) when I specify them as; [Forms]![frmInvoices]![InvoiceNumber] a select query has no problem finding the field values on a form. please help. Aaron Hi Aaron, Could you post the entire code that you are having trouble with? Now it is not possible to see what goes wron...

if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.') Any shorter ?
Hi, there. =20 I'm just curious if it ever dawned on anybody how to abbreviate this line : if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.')=20 =20 Igor Kurbeko Clinical Programmer Analyst 678 336 4328 ikurbeko@atherogenics.com =20 no brain no pain =20 how about: if not (str_mo in ('','.') or str_da in ('','.') or str_yy in ('','.')) OR if not (missing(str_mo) or missing(str_da) or missing(str_yy)) Eric On 22 Oct 03 21:13:37 GMT, ikurbeko@ATHER...

How to turn off 'N', 'S', 'E', 'W'
in the map lat and lon labels? I'm doing a final figure and I really don't need an 'N' after every latitude label, jus the number would suffice. How do I turn of the letters followin the number? What function / toolbox are you refering to?!? Being a little more specific would sure help to get an answer ... Sebastian ...

Parse error: parse error, expecting `','' or `';''
I'm getting the following error Parse error: parse error, expecting `','' or `';'' in /home/notarywe/public_html/php/update2.php on line 108 Here is line 108 <input type="text" name="ud_first" value="<? echo "$first" size="20"?>"></td> Any help would be appreciated. On 3-Aug-2003, "entoone" <entoone@pacbell.net> wrote: > I'm getting the following error Parse error: parse error, expecting `','' > or > `';'' in /home/notarywe/public_h...

A function with 'and' , 'not' , 'null' , 'car' and 'cdr'
What's this ? (defun enigma (x) (and (not (null x)) (or (null (car x)) (enigma (cdr x))))) "I suppose I should learn Lisp, but it seems so foreign." - Paul Graham, Nov 1983 On Wed, Oct 07 2015, CAI GENGYANG wrote: > What's this ? > > > (defun enigma (x) > (and (not (null x)) > (or (null (car x)) > (enigma (cdr x))))) Bad taste? It returns T if the list X contains nil as an element. It would be clearer to write (some #'null x). Helmut CAI GENGYANG ...

How is there an 'error' with 'no message'
I have a form with many fields, each of which has their separate record sources in a split db. Today, several users throughout the afternoon encountered the following message when accessing various dropdowns on the form: "Error (-1517). There is no message for this error." Three questions: 1. Has anyone encountered this error before? 2. If so, how was it overcome? 3. How can MS produce an error message that states : "There is no message for this error"? It would seem to me that if MS has assigned a number to an error, they must know that it can happen. If they k...

Re: if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.') Any shorter ?
OR you could use ARRAY data new; set old; array igor $ (*) str_mo str_da str_yr; do over igor; if igor ~in (' ','.') then do; end; run; Prasad Ravi Igor Kurbeko <ikurbeko@ATHEROGENIC To: SAS-L@LISTSERV.UGA.EDU S.COM> cc: Sent by: "SAS(r) Subject: if str_mo not in ('','.') and str_da not in ('','.') and str_yy ...

Replacing ',' with '.'
Hello, I have a huge amount of numbers in a .txt file. The numbers are in the form 2,43252e+1. I need to replace the , with . How should I do this? I'd prefer some import method that does this during the import procedure. -Janne Hi, I guess you import the data as text and convert it then to numbers. Try 'strrep' before you convert the text to numbers. Tobias Jake the Snake schrieb: > Hello, > > I have a huge amount of numbers in a .txt file. The numbers are in the form 2,43252e+1. I need to replace the , with . How should I do this? I'd prefer some import method...

Web resources about - error fopen('text.txt','w') - comp.soft-sys.matlab

Resources last updated: 1/25/2016 1:32:44 AM