clabacchio
clabacchio

Reputation: 1067

For cycle in Python's way in Matlab

May seem stupid, but after using Matlab for a while (a couple of years), I've tried Python, and despite some Matlab's features that are really handy, I really like Python.

Now, for work, I'm using Matlab again, and sometimes I miss a structure like Python's 'for' loop. Instead of using the standard 'for' that Matlab provides, there is a structure more similar to process batches of similar data?

Upvotes: 1

Views: 296

Answers (2)

glglgl
glglgl

Reputation: 91159

In addition to the given answer, be aware that MATLAB's forloop is very slow.

Maybe programming in a functional style using arrayfun, cellfun() and structfun() might be a handier solution, and quite close to Python's map().

Upvotes: 1

Clement J.
Clement J.

Reputation: 3032

Do you mean something like that?

for val = {'Hello', 'world', '!'}
    disp(val)
end

for val = [1 3 6 9]
    disp(val)
end

Upvotes: 3

Related Questions