Trying to run a photometry program but I keep getting an error I don't quite understand
Show older comments
I'm trying to run this photometry program I made, but I keep running into problems.
The program itself is basically done, I just need to make it able to run now.
%Pcitures
files=dir("C:\Users\Jeff\Documents\MATLAB\Cepheider - fits (1)")
%Offset
offset=importdata('offsets.txt');
offx=offset(:,1);
offy=offset(:,2);
%Orginale pic is image1 'o4201193.10.fts.fts'
hold on;
imshow(image1, [100 650])
%Time data
Time = dlmread('tid.txt');
Time_real = (Time-2455922.728);
%Clip S2
UdklipS2 = image1(142:155,188:202);
%Clip V1
UdklipV1 = image1(233:245,208:222);
%Star S2
startyS2=142;%Top
endyS2=155;%Bot
startxS2=188;%Left
endxS2=202;%Right
Radius_S2 = 7.5;
%Cepheid V1
startyV1=233;%Top
endyV1=248;%Bot
startxV1=208;%Left
endxV1=222;%Right
%Making arrays
Fluxx_V1 =[];%Counts V1
Fluxx_S2 =[];%Counts S2
UdklipV1 =[];
UdklipS2 =[];
MagnitudeV1 =[];
MagnitudeS2 =[];
Times =[];
for i=1:98
images=fitsread(files(i+2).name);
UdklipV1 = images(startyV1+offx(i):endyV1+offx(i),startxV1+offy(i):endxV1+offy(i));
BagrundV1 = images(startyV1+offx(i):endyV1+offx(i),startxV1+offy(i)+14:endxV1+offy(i)+14);%+14 forkydning
Times = [Times, Time_real];
%Photometry
[xV1, yV1]=size(UdklipV1);
ImageSizexV1= xV1; ImageSizeyV1= yV1; RadiusV1= 7;%Dimensions
[xsV1, ysV1]= meshgrid(1:ImageSizexV1, 1:ImageSizeyV1);
circleV1= (xsV1-(endxV1-startxV1)/2).^2+(ysV1-(endyV1-startyV1)/2).^2;%Circle
V1=circleV1*UdklipV1;
Flux_af_V1 = sum(sum(V1));
Bagrund_af_V1 = circleV1'.*BagrundV1;
Flux_bagrund_V1 = sum(sum(Bagrund_af_V1));
Real_fluxV1 = Flux_af_V1-Flux_bagrund_V1;
%Gathering data
Fluxx_V1=[Fluxx_V1, Real_fluxV1];
%Magnitude
MagnitudeV1=[MagnitudeV1, -2.5*log10(Real_fluxV1)];
%Star S2
UdklipS2= images(startyS2+offx(i):endyS2+offx(i),startxS2+offy(i):endxS2+offy(i));
BagrundS2=images(startyS2+offx(i)+13:endyS2+offx(i)+13);startxV1+offy(i):endxV1+offy(i);%
%Photometry
[xS2, yS2]=size(UdklipS2);
ImageSizexS2=xS2; ImageSizeyS2=yS2; RadiusS2 = 7.5;%Dimensions
[xsS2, ysS2]=meshgrid(1:ImageSizexS2, 1:ImageSizeyS2);
circleS2 = (xsS2-(endxS2-startxS2)/2).^2+(ysS2-(endyS2-startyS2)/2).^2;%Circle
S2=circleS2*UdklipS2;
Flux_af_S2 = sum(sum(S2));
Bagrund_af_S2 = circleS2.*BagrundS2;
Flux_bagrundS2 = sum(sum(Bagrund_af_S2));
Real_fluxS2 = Flux_af_S2-Flux_bagrundS2;
%Gathering data
Fluxx_S2=[Fluxx_S2, Real_fluxS2];
%Magnitude
MagnitudeS2=[MagnitudeS2, -2.5*log10(Real_fluxS2)];
end
Magnitude_relationship = (MagnitudeV1-MagnitudeS2);
p = 3.784
fase= mod(Time_real,p)./p;
fig8 = figure(8);
hold on;
plot(fase, Magnitude_relationship, '.');
title('Faseplot')
xlabel('Periode')
ylabel('Delta(M)')
fig9 = figure(9);
hold on;
plot(Time, Magnitude_relationship)
title('Distance modulus asf func. of time')
xlabel('Time')
ylabel('Delta(M)')
But I get the error: Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in Fotometri (line 252)
UdklipS2= images(startyS2+offx(i):endyS2+offx(i),startxS2+offy(i):endxS2+offy(i));
6 Comments
Rik
on 11 Dec 2021
Did you use the debugger to stop execution at that line? That will allow you to calculate the indices. Are you sure the code is doing what you think it is doing?
Jeff Sejr
on 11 Dec 2021
Image Analyst
on 11 Dec 2021
@Jeff Sejr you forgot to attach 'tid.txt'. Also, if the problem doesn't show up until the third data file, you're going to have to give us at least three files.
Jeff Sejr
on 11 Dec 2021
Jeff Sejr
on 11 Dec 2021
Answers (1)
Voss
on 11 Dec 2021
1 vote
offx(14) is -197. startyS2 is 142. So startyS2+offx(i) is -55 when i is 14. So that line is trying to index images starting at row -55, which is not a valid index, hence the error. I would check that your offsets are correct.
9 Comments
Jeff Sejr
on 11 Dec 2021
Jeff Sejr
on 11 Dec 2021
Voss
on 11 Dec 2021
Can you attach the adjusted offsets you tried (i.e., the ones with the high ones set to be less than 35)?
Jeff Sejr
on 11 Dec 2021
Voss
on 11 Dec 2021
Does it still give the same error on the same line? Or some other error when using the modified offsets file?
Thank you. That's actually a different error (previously was "Index in position 1 is invalid. Array indices must be positive integers or logical values.") on a different line (previously was on line 252).
This new error tells me that endyV1+offx(i) is greater than the size of image i in dimension 1. So it's a different error, but it's still caused by apparently incorrect indices.
I guess I would double-check two things:
1) make sure the ith image as returned by dir() corresponds to the ith row of offsets (actually the (i-2)th row of offsets since you skip the '.' and '..'), but the point is that dir() may not give the images in the same order the offsets are in.
2) make sure your expressions for indexing the images are correct. Specifically, you are adding startyV1 to offx(i), which, judging by the names of the variables, is one number relating to the y-direction and one relating to the x-direction. I mean, variable names can be anything, so this is not necessarily a problem; I would just check that these didn't get swapped around somewhere unintentionally.
Jeff Sejr
on 11 Dec 2021
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!