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:
Creating user entry form GUI

Subject: Creating user entry form GUI

From: Ryan

Date: 29 Jun, 2010 20:15:30

Message: 1 of 5

I am trying to create a GUI that will take 2 or 3 inputs which will be strings. These inputs need to be inserted into a text file (which will be executed using linux). How do I write the code to update the text file with these new inputs?

Thanks

Subject: Creating user entry form GUI

From: Sadik

Date: 30 Jun, 2010 02:02:05

Message: 2 of 5

Hi Ryan,

As soon as you say

fid = fopen('yourFile.txt','w');

the contents of your file will be deleted. Now you can go ahead and write anything you want using fprintf.

Best.

Subject: Creating user entry form GUI

From: Ryan

Date: 30 Jun, 2010 15:03:05

Message: 3 of 5

"Sadik " <sadik.hava@gmail.com> wrote in message <i0e8it$oed$1@fred.mathworks.com>...
> Hi Ryan,
>
> As soon as you say
>
> fid = fopen('yourFile.txt','w');
>
> the contents of your file will be deleted. Now you can go ahead and write anything you want using fprintf.
>
> Best.

Thanks. Is there a way that I can just create a few variables in the txt file that will be updated based on the user input? I do not want to delete the entire text file, i just want to replace 3 individual variables that are repeated several times throughout the text file. I know on linux there is a function called "read" which replaces variables in this manner. Are you aware of a similar matlab function?

Subject: Creating user entry form GUI

From: Sadik

Date: 30 Jun, 2010 15:48:04

Message: 4 of 5

Actually, I am not aware of something like that. What you could do is read the whole file, change any portion of it [e.g. parts concerning those parameters] and then write back into it.

Useful functions:
fopen
fclose
fgetl
fscanf
textscan
fread
fprintf
fwrite
---------

Best.

Subject: Creating user entry form GUI

From: ImageAnalyst

Date: 30 Jun, 2010 17:16:47

Message: 5 of 5

On Jun 29, 4:15 pm, "Ryan " <ryanhutten2...@u.northwestern.edu> wrote:
> I am trying to create a GUI that will take 2 or 3 inputs which will be strings. These inputs need to be inserted into a text file (which will be executed using linux). How do I write the code to update the text file with these new inputs?
>
> Thanks

--------------------------------------------------------
Ryan:
Have you looked at inputdlg, like this example from its help:

prompt = {'Enter matrix size:','Enter colormap name:'};
dlg_title = 'Input for peaks function';
num_lines = 1;
def = {'20','hsv'};
answer = inputdlg(prompt,dlg_title,num_lines,def);

Then you insert them into your text file using standard fread() and
fprintf() statements. There are a variety of ways to do this
depending on exactly what you want to do.
-ImageAnalyst

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