# Trying to run a photometry program but I keep getting an error I don't quite understand

3 views (last 30 days)

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

### Answers (1)

Voss
on 11 Dec 2021

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!