MATLAB Answers


Minimizing the use of intermediate variables in functions

Asked by Christopher
on 19 May 2013

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)

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]

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.



No products are associated with this question.

1 Answer

Answer by Azzi Abdelmalek
on 19 May 2013
 Accepted answer



  1 Comment

on 19 May 2013

Ah...its the simple things. Thanks!

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!