0

I'm trying to get the size of an image in matlab, here is the code:

img = imread('folder\image1.jpg');      
size(img);

I'm getting this error :

"Subscript indices must either be real positive integers or logicals"

I dont know why this happens, any help to know the issue would be appreciated

Thanks,

Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
Maystro
  • 2,907
  • 8
  • 36
  • 71
  • If you`re in a script try to provide a variable to your size. Like `mySize = size(img);` – Vuwox Apr 20 '13 at 20:44
  • I tried it, I got the same error – Maystro Apr 20 '13 at 20:45
  • Did img is not null ? `if(img) s = size(img); end` – Vuwox Apr 20 '13 at 20:46
  • Have you create a function name size ? Type `which size` in MatLab command window. Look like the function didn`t found the good implementation. – Vuwox Apr 20 '13 at 20:48
  • actually, the issue disappear now but it didn't enter into this if condition although when I typed img to check if it is empty or not, it returns me values so I'm still not sure what is wrong here and how it didn't enter this condition – Maystro Apr 20 '13 at 20:58
  • Sorry, I don't get it... which if condition? Isn't the code pasted into the question the one that gets you the error? –  Apr 20 '13 at 21:03
  • I mean this if(img) s = size(img); – Maystro Apr 20 '13 at 21:04
  • I got this when I typed which size : size is a variable. – Maystro Apr 20 '13 at 21:08
  • 1
    I think the right way to write that would be `if ~isempty(img), s=size(img); end;` and delete from your workspace any variable called `size`. –  Apr 20 '13 at 21:08
  • I tried something now that might help us find the issue, >> a = [1 1 1;2 2 2]; >> size(a) ans =2 2 2 1 1 1 – Maystro Apr 20 '13 at 21:15
  • Although I clear the history of my commands but the variable size was not cleared but finally when I closed matlab and open it again everything is working properly. Thanks for your help – Maystro Apr 20 '13 at 21:30
  • 2
    No problem. And, just to avoid unnecessary Matlab restarts, an easy way to clear your entire workspace is `clear all`, or `clear classes`. –  Apr 20 '13 at 21:34
  • Also see [this question](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) for [the generic solution to this problem](http://stackoverflow.com/a/20054048/983722). – Dennis Jaheruddin Nov 27 '13 at 16:04

1 Answers1

0

Judging from your comments your error occurs because you overloaded the size function with a variable.

Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122