This short video covers the thought process of rewriting some code for clarity. The six lines of code are lengthened into twice that. The code is much more readable and maintainable. The problem is not as important as the thought process, however, the problem is about reshaping a matrix.
rowStart and indeed numSubMat should be variables that change depending on the numSubRows variable, otherwise if you change numSubRows in your code then it will no longer give the expected output
By the way, I notice there is an M-lint warning on line 54 complaining about the [x:y] syntax. Why is that considdered a warning? As your example shows, code usually ends up having them, and I see no reason why Matlab should have a problem with that.
The code would be better with that suggestion, slightly more complicated, but a good check as that is something that would likely be done wrong by coders working with the code later.
@Daniel,
The complaint on 54 is about using unneeded brackets on that line. The code runs just as well without them.
@dhull
Yes, but so are an extra pair of parenthesis, but sometimes you leave them in there anyways and you do not see matlab complaining. But that is a discussion to be had in a service request, not here.
I suspect the reason why MLint doesn’t warn about parenthesis is that they invoke no function call. Parenthesis are only used to group in this context. Brackets on the other hand, are used to concatenate. If there is only one array inside the brackets, there is nothing to concatenate, yet the internal concatenate function is called anyway! This is an inefficiency.
Hi, I’m new to this blog, and as a matter of fact I’m lost so I was kinda hoping someone will point to me the right link to post my questions about SimEvent tool box.
rowStart and indeed numSubMat should be variables that change depending on the numSubRows variable, otherwise if you change numSubRows in your code then it will no longer give the expected output
@Robert
aw! yeah you’re right bro.. thank you for this advice…
By the way, I notice there is an M-lint warning on line 54 complaining about the [x:y] syntax. Why is that considdered a warning? As your example shows, code usually ends up having them, and I see no reason why Matlab should have a problem with that.
–DA
@Robert,
The code would be better with that suggestion, slightly more complicated, but a good check as that is something that would likely be done wrong by coders working with the code later.
@Daniel,
The complaint on 54 is about using unneeded brackets on that line. The code runs just as well without them.
-Thanks
Doug
@dhull
Yes, but so are an extra pair of parenthesis, but sometimes you leave them in there anyways and you do not see matlab complaining. But that is a discussion to be had in a service request, not here.
Daniel Armyr,
I suspect the reason why MLint doesn’t warn about parenthesis is that they invoke no function call. Parenthesis are only used to group in this context. Brackets on the other hand, are used to concatenate. If there is only one array inside the brackets, there is nothing to concatenate, yet the internal concatenate function is called anyway! This is an inefficiency.
Hi, I’m new to this blog, and as a matter of fact I’m lost so I was kinda hoping someone will point to me the right link to post my questions about SimEvent tool box.
Thanks a lot in advance.
Ola,
http://www.mathworks.com/support can answer all your questions.
Thanks,
Doug
I’ve been using Matlab for a long time, but never thought of coding a test matrix like you did, e.g.,
1 2 3 4 …
11 12 13 14 …
.
.
.
Great idea for checking how code manipulates data, in stages