Dear all,
what is wrong with this code:
clear mata
mata
function task3(real vector x) {
real scalar i
real scalar n
real scalar r
real scalar c
r = rows(x)
c = cols(x)
if (c == 1) {
n = r
X=J(1,1,.)
}
if (r == 1) {
n = c
Y=J(1,1,.)
}
for(i=1; i<=n; i = i + 2) {
X = sum(i+i)
Y = sum(i+i)
}
return(X)
return(Y)
}
x = (1,2,4,7,5,6)
task3(x)
end
If I add or change numbers, this code is not working.
Thank you.
what is wrong with this code:
clear mata
mata
function task3(real vector x) {
real scalar i
real scalar n
real scalar r
real scalar c
r = rows(x)
c = cols(x)
if (c == 1) {
n = r
X=J(1,1,.)
}
if (r == 1) {
n = c
Y=J(1,1,.)
}
for(i=1; i<=n; i = i + 2) {
X = sum(i+i)
Y = sum(i+i)
}
return(X)
return(Y)
}
x = (1,2,4,7,5,6)
task3(x)
end
If I add or change numbers, this code is not working.
Thank you.
Comment