Subscript indices must either be real positive integers or logicals
1 view (last 30 days)
Show older comments
elena rondina
on 26 Jan 2016
Edited: Image Analyst
on 26 Jan 2016
hello recently I'm learning matlab. i have this problem:
j = read(img);
u=im2bw(img);
imshow(u);
and main:
if[imgName,path] = uigetfile('*.jpg','Select the MATLAB code file');
img=imread([path imgName]);
j =read(img );
matlab error:Subscript indices must either be real positive integers or logicals. how can I read an image by main function that using other read function?
4 Comments
Accepted Answer
Image Analyst
on 26 Jan 2016
Edited: Image Analyst
on 26 Jan 2016
Why do you have "if" in this line:
if[imgName,path] = uigetfile('*.jpg','Select the MATLAB code file');
Try getting rid of that if, and just start with the brackets. Or better yet, try more robust code like this:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Program Files\MATLAB'; % Wherever you want....
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.jpg');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
Also, read the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F about that error message.
0 Comments
More Answers (0)
See Also
Categories
Find more on Search Path in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!