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..)

 채택된 답변

Adam
Adam 2014년 9월 10일

0 개 추천

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

Shane
Shane 2014년 9월 10일
Yes the vectors in VarName1 and and VarName2 are length 12. I tried this and it still says Index exceeds matrix dimensions.
Adam
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.
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2014년 9월 10일

댓글:

2014년 9월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by