Loading either one or multiple images Matlab GUI











up vote
1
down vote

favorite












I want to load multiple images in Matlab GUI. Algorithm below:



 % --- Executes on button press in pushbutton1.
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)
[filename path] = uigetfile('*.jpg','*.png','Chose files to
load','MultiSelect','on');
if isequal(filename,0) || isequal(path,0)
return
end
if iscell(filename)
img = cell(size(filename));
for ii = 1:numel(filename)
img{ii} = imread(fullfile(path,filename{ii}));
end
else
img{1} = imread(fullfile(path,filename));
end
filename = strcat(path,filename);
fullpathname = strcat(path, filename);
set(handles.edit1,'String', fullpathname);
fileID = fopen(strcat(path, filename), 'r');


I also need the directory of an image or images to bee seen text box, but it gives me subsequent error:



Error using imread>parse_inputs (line 457)
The file name or URL argument must be a string.
Error in imread (line 316)
[filename, fmt_s, extraArgs] = parse_inputs(varargin{:});
Error in untitled>pushbutton1_Callback (line 112)
im = rgb2gray(imread(filename));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in untitled (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)
untitled('pushbutton1_Callback',hObject,eventdata,guidata(hObject))


Could you please give me a hint, what and how I can customize the algorithm to make it functional?










share|improve this question


























    up vote
    1
    down vote

    favorite












    I want to load multiple images in Matlab GUI. Algorithm below:



     % --- Executes on button press in pushbutton1.
    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)
    [filename path] = uigetfile('*.jpg','*.png','Chose files to
    load','MultiSelect','on');
    if isequal(filename,0) || isequal(path,0)
    return
    end
    if iscell(filename)
    img = cell(size(filename));
    for ii = 1:numel(filename)
    img{ii} = imread(fullfile(path,filename{ii}));
    end
    else
    img{1} = imread(fullfile(path,filename));
    end
    filename = strcat(path,filename);
    fullpathname = strcat(path, filename);
    set(handles.edit1,'String', fullpathname);
    fileID = fopen(strcat(path, filename), 'r');


    I also need the directory of an image or images to bee seen text box, but it gives me subsequent error:



    Error using imread>parse_inputs (line 457)
    The file name or URL argument must be a string.
    Error in imread (line 316)
    [filename, fmt_s, extraArgs] = parse_inputs(varargin{:});
    Error in untitled>pushbutton1_Callback (line 112)
    im = rgb2gray(imread(filename));
    Error in gui_mainfcn (line 95)
    feval(varargin{:});
    Error in untitled (line 42)
    gui_mainfcn(gui_State, varargin{:});
    Error in
    @(hObject,eventdata)
    untitled('pushbutton1_Callback',hObject,eventdata,guidata(hObject))


    Could you please give me a hint, what and how I can customize the algorithm to make it functional?










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I want to load multiple images in Matlab GUI. Algorithm below:



       % --- Executes on button press in pushbutton1.
      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)
      [filename path] = uigetfile('*.jpg','*.png','Chose files to
      load','MultiSelect','on');
      if isequal(filename,0) || isequal(path,0)
      return
      end
      if iscell(filename)
      img = cell(size(filename));
      for ii = 1:numel(filename)
      img{ii} = imread(fullfile(path,filename{ii}));
      end
      else
      img{1} = imread(fullfile(path,filename));
      end
      filename = strcat(path,filename);
      fullpathname = strcat(path, filename);
      set(handles.edit1,'String', fullpathname);
      fileID = fopen(strcat(path, filename), 'r');


      I also need the directory of an image or images to bee seen text box, but it gives me subsequent error:



      Error using imread>parse_inputs (line 457)
      The file name or URL argument must be a string.
      Error in imread (line 316)
      [filename, fmt_s, extraArgs] = parse_inputs(varargin{:});
      Error in untitled>pushbutton1_Callback (line 112)
      im = rgb2gray(imread(filename));
      Error in gui_mainfcn (line 95)
      feval(varargin{:});
      Error in untitled (line 42)
      gui_mainfcn(gui_State, varargin{:});
      Error in
      @(hObject,eventdata)
      untitled('pushbutton1_Callback',hObject,eventdata,guidata(hObject))


      Could you please give me a hint, what and how I can customize the algorithm to make it functional?










      share|improve this question













      I want to load multiple images in Matlab GUI. Algorithm below:



       % --- Executes on button press in pushbutton1.
      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)
      [filename path] = uigetfile('*.jpg','*.png','Chose files to
      load','MultiSelect','on');
      if isequal(filename,0) || isequal(path,0)
      return
      end
      if iscell(filename)
      img = cell(size(filename));
      for ii = 1:numel(filename)
      img{ii} = imread(fullfile(path,filename{ii}));
      end
      else
      img{1} = imread(fullfile(path,filename));
      end
      filename = strcat(path,filename);
      fullpathname = strcat(path, filename);
      set(handles.edit1,'String', fullpathname);
      fileID = fopen(strcat(path, filename), 'r');


      I also need the directory of an image or images to bee seen text box, but it gives me subsequent error:



      Error using imread>parse_inputs (line 457)
      The file name or URL argument must be a string.
      Error in imread (line 316)
      [filename, fmt_s, extraArgs] = parse_inputs(varargin{:});
      Error in untitled>pushbutton1_Callback (line 112)
      im = rgb2gray(imread(filename));
      Error in gui_mainfcn (line 95)
      feval(varargin{:});
      Error in untitled (line 42)
      gui_mainfcn(gui_State, varargin{:});
      Error in
      @(hObject,eventdata)
      untitled('pushbutton1_Callback',hObject,eventdata,guidata(hObject))


      Could you please give me a hint, what and how I can customize the algorithm to make it functional?







      matlab matlab-guide






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 13:21









      Franta Mráz

      63




      63
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          One reason for the code to fail is that once you merge the filename and the path you miss a / (or depending on which OS you are working). Therefore you should use fullfile(path,filename) instead of strcat(path,filename).






          share|improve this answer























          • Works. Thank you!
            – Franta Mráz
            Nov 7 at 14:23










          • I'm happy to hear that @FrantaMráz!
            – Pablo Jeken
            Nov 7 at 15:51











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53190322%2floading-either-one-or-multiple-images-matlab-gui%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          One reason for the code to fail is that once you merge the filename and the path you miss a / (or depending on which OS you are working). Therefore you should use fullfile(path,filename) instead of strcat(path,filename).






          share|improve this answer























          • Works. Thank you!
            – Franta Mráz
            Nov 7 at 14:23










          • I'm happy to hear that @FrantaMráz!
            – Pablo Jeken
            Nov 7 at 15:51















          up vote
          1
          down vote



          accepted










          One reason for the code to fail is that once you merge the filename and the path you miss a / (or depending on which OS you are working). Therefore you should use fullfile(path,filename) instead of strcat(path,filename).






          share|improve this answer























          • Works. Thank you!
            – Franta Mráz
            Nov 7 at 14:23










          • I'm happy to hear that @FrantaMráz!
            – Pablo Jeken
            Nov 7 at 15:51













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          One reason for the code to fail is that once you merge the filename and the path you miss a / (or depending on which OS you are working). Therefore you should use fullfile(path,filename) instead of strcat(path,filename).






          share|improve this answer














          One reason for the code to fail is that once you merge the filename and the path you miss a / (or depending on which OS you are working). Therefore you should use fullfile(path,filename) instead of strcat(path,filename).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 7 at 14:06

























          answered Nov 7 at 13:47









          Pablo Jeken

          429114




          429114












          • Works. Thank you!
            – Franta Mráz
            Nov 7 at 14:23










          • I'm happy to hear that @FrantaMráz!
            – Pablo Jeken
            Nov 7 at 15:51


















          • Works. Thank you!
            – Franta Mráz
            Nov 7 at 14:23










          • I'm happy to hear that @FrantaMráz!
            – Pablo Jeken
            Nov 7 at 15:51
















          Works. Thank you!
          – Franta Mráz
          Nov 7 at 14:23




          Works. Thank you!
          – Franta Mráz
          Nov 7 at 14:23












          I'm happy to hear that @FrantaMráz!
          – Pablo Jeken
          Nov 7 at 15:51




          I'm happy to hear that @FrantaMráz!
          – Pablo Jeken
          Nov 7 at 15:51


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53190322%2floading-either-one-or-multiple-images-matlab-gui%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini