MATLAB: Index exceeds matrix dimensions.

hsihyperspectralmatrix

Hear is my code
%%Get Full Image Data
% ENVI Import Cube and Register images
datafile = '0604img-17_FlatField';
hdrfile = '0604img-17_FlatField.hdr';
%%Read ENVI Files
[im, hdr] = enviread([old '\' datafile],[old '\' hdrfile]);
img = imrotate(im,90, 'nearest');
figure; imshow(img(:,:,124));
%d = reshape(textread('listplot.txt', '%s'),1,12)';
%list of coordinates as x and y
load('listp.txt');
for i = 1:12
% pixval(i) = i+ img(d,:);
pixval(i) = i+ img(VarName1,VarName2,:);
end
It says it exceeds matrix dimentions. Some info: the "load (listp.txt) " outputs 2 list VarName1 12×1 double and VarName2 12×1 double. What i was doing before to call the information was to
pixval = img(74,100,:)
this gave me a 1x1x361 matrix with all the data of that point. What I want to do is store the multiple points without having to create a variable for each (I.E. pixval1, pixval2 ext..)

Best Answer

By the sounds of it you want:
pixval(i) = i+ img(VarName1(i),VarName2(i),:);
rather than using the full VarName1 and VarName2 every time if they are length 12 vectors.