Need help in uderstanding this piece of code
Show older comments
Hello All, This is the code I found somewhere in a script :
output(idx,:) = [y1(ii),z,smax];
Can anyone explain me the logic here? I mean what's expected out of this code?
1 Comment
These are all very basic MATLAB operations: indexing, concatenation, and assigning to variables. You should do the introductory tutorials, which introduce these basic MATLAB operations:
Accepted Answer
More Answers (1)
You generate a row vector
[y1(ii),z,smax]
And this vector is assigned to row "idx" of the output matrix
output(idx,:) = [y1(ii),z,smax];
You cannot do
output(idx) = [y1(ii),z,smax];
because you cannot assign a 1xN vector to a single number output(idx). So you need the ,: to assign the vector to a row.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!