what it mean s(1) and s(2)

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;

1 Commento

Guillaume
Guillaume il 27 Feb 2016
Modificato: Guillaume il 27 Feb 2016
Here is an equation:
a = b + c
What are a, b, and c? Who knows? Only the original author knows. Same with your piece of code. Go and ask the author.
edit: And how come you're using a piece of code if you don't even know what it does?
edit2: And it's a totally useless piece of code in any case. The two outer loops overwrite the same variable, so actually do nothing until the last iteration. The two inner loops are a very inefficient way of copying part of a matrix. All in all, the whole code is the same as:
mat = temp(s(1)-10:s(1)+2*n-10, s(2)-10:s(2)+2*n-10)

Accedi per commentare.

 Risposta accettata

Stephen23
Stephen23 il 27 Feb 2016
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

Più risposte (0)

Prodotti

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by