0

I have a GUI with 5 axes in it, where images which are stored in text file(notepad) are displayed. Images in text file are not static, it keeps updating with new ones. I mean for first search images are different and after closing all windows again if i run same program for next search different images may get saved in notepad.

function displayResults(filename, header)

figure('Position',[200 100 700 400], 'MenuBar', 'none', 'Name', header, 'Resize',     'off', 'NumberTitle', 'off');

% Open 'filename' file... for reading...
fid = fopen(filename);
for N=1:5
    imagename = fgetl(fid);
    if ~ischar(imagename), break, end       % Meaning: End of File...

     (x) = imread(imagename);
     axes(handles.axesN);
     imshow(fname);
     xlabel(imagename);
end
fclose(fid);

filename is text file

I need to fit these images on all 5 axes, but I'm getting error like undefined variable handles.axesN How can i go for it?

Chethan
  • 213
  • 3
  • 7
  • 19

1 Answers1

0

Some questions:

(1) What are the names of your axes? axes1, ..., axes5? In that case do, e.g.

axes(eval(['handles.axes', num2str(N)]));

(2) Why (x) = imread(imagename) and later imshow(fname)? Shouldn't it be

img = imread(imagename);
% ...
imshow(img);

(3) Where do you get handles from? You need to pass it to the function.

matheburg
  • 2,097
  • 1
  • 19
  • 46
  • 2
    better use dynamic field names than `eval`, i.e: `handles.(sprintf('axes%d',N))` – Amro Apr 27 '13 at 17:54
  • `displayResults` is a separate function and how can i pass `handles` to this function? – Chethan Apr 28 '13 at 05:45
  • If you call your function from some event called function, e.g. `function pushbutton1_Callback(hObject, eventdata, handles)`. You can pass it on the same way to your function: `function displayResults(filename, header, handles)`. For more details we would need a minimal example how and where you call your display function. – matheburg Apr 28 '13 at 07:22
  • My calling function is `displayResults('colourResults.txt','color search. . .');` which is present in `fig5` GUI-M file and `figure('Position',[200 100 700 400], 'MenuBar', 'none', 'Name', header, 'Resize', 'off', 'NumberTitle', 'off');` will open a new window with stated header. but i don't want to display images in new window, instead i want to display those on axes in my GUI `fig5` figure – Chethan Apr 28 '13 at 17:25
  • my question is: Where is displayResults called from? From some Event Function from `fig5` I guess? – matheburg Apr 29 '13 at 14:30
  • `displayresults` is called from `FIG5` yeah. now i changed my program , i copied `displayresults` to FIG5 function only. I've used `axes(handles.(sprintf('axes%d', N)));` this, and i removed `figure('position'. . .)` line since i don't need a new window. now i'm getting error `??? Undefined variable "handles" or class "handles.axes".` – Chethan May 02 '13 at 05:01
  • The error is very self-explanatory. You have to pass `handles` to your function. Wherever you call your function from (you again didn't tell me in your last post!) I guess there `handles` is available, so call your function via `displayresults(..., handles)` and change your function header to `function displayResults(filename, header, handles)`. Then it should be available to your function... – matheburg May 03 '13 at 15:12