Index exceeds matrix dimensions. ?
1 次查看(过去 30 天)
显示 更早的评论
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..)
0 个评论
采纳的回答
Adam
2014-9-10
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 个评论
Adam
2014-9-10
编辑:Adam
2014-9-10
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!