1
votes

Continuing my struggle against GUI's, I have run into another road block.

Ive successfully created a button that opens a file as a string, and places it in a text box in my GUI like so.

 [filename, pathname] = ...
     uigetfile({'*.m';'*.mdl';'*.mat';'*.*'},'File Selector');

set(handles.Textbox1, 'string', fullfile(pathname,filename));

But now I cannot seem to use a function on the acquired file. Ive tried doing

  str = get(handles.Textbox1,'string');
Histogram(str); %Histogram is a function that I created.

But im getting the following errors

??? Error using ==> Histogram Too many input arguments.

Error in ==> VarunGUI>pushbutton2_Callback at 94 Histogram(str);

Error in ==> gui_mainfcn at 96 feval(varargin{:});

Error in ==> VarunGUI at 42 gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)VarunGUI('pushbutton2_Callback',hObject,eventdata,guidata(hObject))

??? Error while evaluating uicontrol Callback

Is my code for calling the function to blame, or is the function itself? I'm having trouble understanding how to alter the function to work on the called image, so that may be my problem, the function begins with the following code.

function Histogram
clear;
clc;
fid = fopen('');
myimage = fread(fid, [512, 683], '*uint8');
fclose(fid);

Is there a certain variable I need to place in the '' to make the GUI act in the manner to which I would like it? Question ran a little long, but please tell me if there is anything else you need to see in order to assist me, any guidance or tips would be great. Thanks!

3
Have you tried using dbstop if error and figuring out where exactly strange things become visible? - Dennis Jaheruddin

3 Answers

2
votes

You're problem is that call Histogram and pass it str:

Histogram(str)

But you don't define Histogram to expect input:

function Histogram

What you need is something like this:

function Histogram(str)

% do something with str
3
votes

Your Histogram function doesn't have an input, so it fails when you call it : Histogram(str)

1
votes

I got this y'all!

Change your histogram function to this: (literally copy and paste what's below)

function Histogram(str) %Add input argument
%clear %DO NOT USE CLEAR in a function, the benefit of using a function is you don't have to %clear anything :)
clc;
fid = fopen(str); %Use input argument
myimage = fread(fid, [512, 683]); %take off *uint8
fclose(fid);

Read MATLAB's documentation, it is fantastic, and would allow you to see why fread and uint8 don't go together in a matter of seconds (seriously less than 20 seconds would give you your answer) and it would also solve all your other extremely basic issues you are having.