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:
Edit Text GUI

Subject: Edit Text GUI

From: Garrett

Date: 11 Jul, 2010 16:05:05

Message: 1 of 4

I am trying to use an edit text box to input a file name so that I can then read the file in when I use a push button.

Code:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
c = get(handles.edit1,'string')
x = dlmread(c,' ');

I then get this error:

??? Error using ==> dlmread at 55
Filename must be a string.

Error in ==> untitled1>pushbutton1_Callback at 82
x = dlmread(c,' ');

As far as I can tell the error is happening because there is an extra set of apostrophes on each end of the filename I input.

So i input filename.asc into the edit text field of the GUI but when dlmread tries to access the variable c, which should just be the string in the edit field, it comes out as 'filename.asc'. Anyone know how to keep this extra set of apostrophes from showing up?

-Garrett

Subject: Edit Text GUI

From: Garrett

Date: 11 Jul, 2010 16:30:29

Message: 2 of 4

Nevermind I figured it out, just needs a char(get(handlestuff));

Subject: Edit Text GUI

From: Jan Simon

Date: 11 Jul, 2010 19:40:20

Message: 3 of 4

Dear Garrett,

> I am trying to use an edit text box to input a file name so that I can then read the file in when I use a push button.

> c = get(handles.edit1,'string')
> x = dlmread(c,' ');
> ??? Error using ==> dlmread at 55
> Filename must be a string.

You can use the debugger (e.g. "dbstop if error") to find out, that after
  c = get(handles.edit1,'string')
c is a cell string and not a CHAR vector. Using CHAR converts a cell string to a string, as you have posted already. Another way would be:
  name = c{1};
  x = dlmread(c,' ')

Good luck, Jan

Subject: Edit Text GUI

From: Garrett

Date: 11 Jul, 2010 20:05:05

Message: 4 of 4

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <i1d6n4$kjm$1@fred.mathworks.com>...
> Dear Garrett,
>
> > I am trying to use an edit text box to input a file name so that I can then read the file in when I use a push button.
>
> > c = get(handles.edit1,'string')
> > x = dlmread(c,' ');
> > ??? Error using ==> dlmread at 55
> > Filename must be a string.
>
> You can use the debugger (e.g. "dbstop if error") to find out, that after
> c = get(handles.edit1,'string')
> c is a cell string and not a CHAR vector. Using CHAR converts a cell string to a string, as you have posted already. Another way would be:
> name = c{1};
> x = dlmread(c,' ')
>
> Good luck, Jan


Thanks for the explanation, that makes more sense now. Is there a reason that after I push the calculate button I also have to hit enter in the command line for the dlmread to initialise?

Tags for 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