title: error: " Attempt to reference field of non-structure array." in Matlab? error snap at end of code
body: <p>I am writing a MATLAB code for detection of different color toys</p>
  
  <p>I will be using below image in my code with name"toys.jpg"</p>
  
  <p><a href="https://i.stack.imgur.com/JSCY4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JSCY4.jpg" alt="enter image description here"></a></p>
  
  <p>My matlab code is as follow</p>
  
  <pre><code>clc;clear all;close all;
  %Making matrix for 4 colors
  MatrixR=[0,0,0,0,1,1,1,1];
  MatrixG=[0,0,1,1,0,0,1,1];
  MatrixB=[0,1,0,1,0,1,0,1];
  %B,Blue,G,C,R,P,Y,W
  RGBMatrix=uint8(255*((cat(3,MatrixR,MatrixG,MatrixB))));
  %Converting these matrix to Gray
  GrayVersion=((rgb2gray(RGBMatrix)));
  %Plotting
  subplot 211
  imshow(RGBMatrix,[0 255]);
  title('RGB matrix of toys color');
  subplot 212
  imshow(GrayVersion,[0 255]);
  title('Grayscale mapping of RGB matrix');
  %Reading ToyImage
  ToyImage=uint8(imread('toys.jpg'));
  %Placing Cursor
  dcm_obj1 = datacursormode(figure);
  imshow(ToyImage,[]);
  datacursormode on
  fprintf('Select the toy from the Image Displayed\n');
  waitforbuttonpress;
  c_info = getCursorInfo(dcm_obj1);
  position=c_info.Position; %extracting position for finding toy
  grayValueFromImage=double(ToyImage(position(2),position(1)));
  %Formula
  red=abs(double(GrayVersion(5))-grayValueFromImage); green=abs(double(GrayVersion(3))-grayValueFromImage);
  blue=abs(double(GrayVersion(2))-grayValueFromImage); yellow=abs(double(GrayVersion(7))-grayValueFromImage);
  %Condition
  minimumAmongArray=min([red,blue,green,yellow]);
  fprintf('At Position \n');
  disp(position);
  if(minimumAmongArray==red)
  fprintf('The selected toy has Red Color\n');
  end
  if(minimumAmongArray==green)
  fprintf('The selected toy has Green Color\n');
  end
  if(minimumAmongArray==blue)
  fprintf('The selected toy has Blue Color\n');
  end
  if(minimumAmongArray==yellow)
  fprintf('
  The selected toy has Yellow Color\n');
  end
  </code></pre>
  
  <p>But when i try to execute above code, i get error: "  Attempt to reference field of non-structure array" </p>
  
  <p><a href="https://i.stack.imgur.com/fGT1R.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fGT1R.jpg" alt="t end "></a></p>