MATLAB: What it mean s(1) and s(2)

simulinkvariables

Hello guys. I found a matlab code and in this code we have 2 variables called s(1) and s(2). my question is what are the 2 variables s(1) and s(2) ? What mean s(1) and s(2) ? here the code:
r=s(1);
c=s(2);
for x=(n+1+10):(s(1)+n-10)
for y=(n+1+10):(s(2)+n-10)
e=1;
for k=x-n:x+n
f=1;
for l=y-n:y+n
mat(e,f)=temp(k,l);
f=f+1;
end
e=e+1;
end;
end;
end;

Best Answer

Judging by the context s is most likely just one variable, and the code simply accesses the first and second elements of the variable using indexing. Indexing is a very basic concept in mathematics and computer science, which you need to learn about if you want to use MATLAB:
Judging by the context and the names of the variable they are being allocated into, the first and second elements represent the rows and columns of another variable, something like this:
>> M = rand(4,5); % define a matrix
>> S = size(M); % gets its size
>> S(1) % the number of rows of M
ans =
4
>> S(2) % the number of columns of M
ans =
5
Related Question