Index exceeds matrix dimensions. ?

1 Ansicht (letzte 30 Tage)
Shane
Shane am 10 Sep. 2014
Kommentiert: Shane am 10 Sep. 2014
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 12x1 double and VarName2 12x1 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..)

Akzeptierte Antwort

Adam
Adam am 10 Sep. 2014
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.
  3 Kommentare
Adam
Adam am 10 Sep. 2014
Bearbeitet: Adam am 10 Sep. 2014
Well, I guess the obvious next question is what is the range of the values in VarName1 and VarName2 relative to img?
Actually, looking at it again I imagine the error comes from the pixval(i) assignment.
img(VarName1,VarName2,:) is going to return a vector of values so I imagine you need:
pixval(i,:) = i + squeeze( img(VarName1(i),VarName2(i),:) );
or something similar to that.
You should probably pre-allocate pixval too, but that is just for efficiency and isn't going to affect whether the code works or not in this case.
Shane
Shane am 10 Sep. 2014
Thanks Adam, this gave me direction for what I needed to change to make it work
pixval=zeros(361,12);
for i = 1:12
pix = img(VarName2(i),VarName1(i),:);
pixval(:,i)=pix(:);
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by