Minimizing the use of intermediate variables in functions

2 views (last 30 days)
Is there a way to do this in Matlab?
I'd like to grab the size of an array and use it in a for loop. The following works:
k = size(array)
for i = 1:k(2)
statements;
end
However, its a bit cumbersome to do. I'd like to do the following instead, but every combination I try always gives me errors:
for i = 1:size(array)[2]
statements;
end
I get the syntax here is off, but there does not seem to be a way to take the return of the "size" function (an array) and grab the second index from it. I'd like to be able to do this, if possible, to prevent the need for using a bunch of intermediate variables like "k" in the first example.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 19 May 2013
Use
size(array,2)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!