Dear list members,

I need to translate 3 lines of matlab code to R (a loop, to be specific),
and I don't know what would be the results in matlab or how to do it in R--
I don't realise if they are doing to the col, vector or what. if the results
are a vector or a value or a matrix :-(

Anyone with matlab, can run it and give me the result? Any ideias what am I
doing wrong?
The code is bellow...I have put the matlab code, followed by what I think
would be the R code .

Any help would be greatly appreciated,
Thank you very much in advance,
Best wishes,
Marta
*
# from Rubin 2004: The following example opens an image (line 1), displays
the image (line 2),
# converts the image to grayscale data (line 3), and calculates the
autocorrelation curve
# for offset distances of one pixel to 99 pixels (lines 7–10). This code can
be used to
# perform steps (4) and (6) listed above in the Summary of Steps to
Calculate Grain
# Size of Natural Sediment.

ColorData = imread(‘ImageName.jpg’); x <- read.jpeg("sed2.jpg")# opens the
image
imshow(ColorData); plot(x) # plot image
data = double(rgb2gray(ColorData)); x=rgb2grey(x) # transform in grayscale,
the image
; # example of a similar data matrix: data =
double(0.54878431372549,0.468,0.553411764705882,0.663529411764706,
0.440156862745098,0.330313725490196,0.473843137254902,0.690980392156863,
0.483333333333333,0.344862745098039,0.458156862745098,0.647843137254902)
ImageWidth = size(data,2); dim(A)[2] # i.e. number of col
MaxOffset = 99; # defined variable, =2R
ImageWidthToProcess = ImageWidth-MaxOffset; # =2R defined variable
for Offset = 1:MaxOffset ; loop to calculate the autocorrelation. basicly,
they do cor2, which I think is Spearman correlation, between every column
and store it in the vector position???
    OffsetPlaquette = data(:,1+Offset:ImageWidthToProcess+Offset);
    AutoCData(Offset) = corr2(data(:,1:ImageWidthToProcess),
OffsetPlaquette)
end

# IN R would be... but it is not correct! What would be the results in
matlab? and how to do it in R?
for(Offset in 1:MaxOffset){
    OffsetPlaquette = x[,1+Offset:ImageWidthToProcess+Offset]
    AutoCData[Offset] = cor(c(x[,1:ImageWidthToProcess]),
c(OffsetPlaquette))
}
*

	[[alternative HTML version deleted]]

