Problem with GUI for import .txt file

Hellow,
I'm trying to use the explanation of the following link to link through csv, matlab and metatrader. https://www.mql5.com/es/articles/1489
I made the first steps, but when entering the code:
% --- Executes on button press in pushBrowse.
function pushBrowse_Callback(hObject, eventdata, handles)
[fileName, filePath] = uigetfile('*.txt'); % receive and the path from the user
if fileName==0 % if it is canceled
fileName=''; % create an empty name
filePath=''; % create an empty path
end
fullname = [filePath fileName] % form a new name
set(handles.editPath,'String', fullname); % write in the editPath
It gives me the following error:
fullname =
H:\FXPRO4\MQL4\Files\EURUSD.txt
Attempt to reference field of non-structure array.
Error in FromfTo>pushBrowse_Callback (line 107)
set(handles.editPath,'String', fullname); % write in the editPath
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in FromfTo (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)FromfTo('pushBrowse_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Therefore, the first step towards choosing the file path is blocked by pressing the Browse button
Anyone know what's wrong?
Thank you very much

5 Comments

Adam
Adam on 8 May 2015
Edited: Adam on 8 May 2015
Have you used the debugger to see what is happening on that line? It is usually faster than asking for an answer.
I can't see anything obviously wrong, but the error message suggests that 'handles' is not a structure which would imply that somewhere else in your code you have accidentally overwritten the handles structure with something else.
I just filled out the code for the Browse button.
To check is really good, I press Browse and gives me this error.
I will say a little better, because the code suggests having also set the Start button for at least import the data and be read:
% --- Executes on button press in pushBrowse.
function pushBrowse_Callback(hObject, eventdata, handles)
[fileName, filePath] = uigetfile('*.txt'); % receive and the path from the user
if fileName==0 % if it is canceled
fileName=''; % create an empty name
filePath=''; % create an empty path
end
fullname = [filePath fileName] % form a new name
set(handles.editPath,'String', fullname); % write in the editPath
% --- Executes on button press in pushStart.
function pushStart_Callback(hObject, eventdata, handles)
process(handles);
% data reading, chart drawing, processing, storage
function process(handles)
fullname = get(handles.editPath, 'String'); % read the name from editPath
data = dlmread(fullname, ';', 2, 2); % read the matrix from file
info = ['Last update: ' datestr(now)]; % form an informative message
set(handles.textInfo, 'String',info); % write info into the status bar
high = data(:,1); % it is now high where the first column of the data
matrix is
low = data(:,2); % d low -- the second
close = data(:,3); % --/--
open = data(:,4); %
len = length(open); % the amount of elements in open
axes(handles.axesChart); % make the axes active
hold off; % clean axes off before adding a new chart
candle(high, low, close, open); % draw candlesticks (in the current axes)
set(handles.axesChart,'XLim',[1 len]); % set limits for charting
This is the necessary code. I think it's fine, I checked many times but "Matlab" gives me error.
I started recently with GUI, but I think the code is correct
Thank you very much for your reply
That brings me back to my original question then of have you used the debugger? Most of the time it is obvious what the problem is by debugging so there's no point working in the dark by just trying to guess.
And I used the debugging.
On line 131 I have the error:
axes(handles.axesChart);
And the message is:
"Reference to non-existent field 'axesChart'."
i dont understand this error
That is just running the code and getting an error though.
Debugging allows you to actually look at the 'handles' variable on the command line if you put a breakpoint in.
Then it will be obviously if 'handles' is what it is supposed to be. The error clearly tells you that 'handles' does not have that field though so double-check your axes tag.

Sign in to comment.

 Accepted Answer

In step 3 of that document it says to use the visual properties builder to create several objects, including:
Axes: Box on, FontName – MS Sans Serif, FontSize – 8, Tag - axesChart.
You either did not do that or else you did not set the Tag to be exactly 'axesChart'

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!