for loop like c++ in MATLAB

8 views (last 30 days)
Hamid
Hamid on 12 Jan 2014
Edited: Hamid on 19 Jul 2014
for loop in C or C++ is very flexible and fast. Why MATLAB doesn't create a for loop like C or C++?
  1 Comment
Hamid
Hamid on 25 Jan 2014
Edited: Hamid on 25 Jan 2014
In general, problem of MATLAB is in for loops that cause some slowness. If while loops are used instead of for loops, speed will be increased very much (some complicated tests can be very interesting) and additionally, while loops are more flexible than for loops and therefore, MATLAB, will be an excellent friend for a programmer with very complicated mathematical calculations and operations. Additionally, because of existence of MATLAB Coder toolbox, it's unnecessary to follow C++ for these complicated calculations. In fact, in early future, C++ with respect to MATLAB, will be like Assembly with respect to C++. Only MATLAB. Thanks God for such a powerful software and I wish God's attentions and helps for its kind engineers.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 12 Jan 2014
I'm not sure I understand what you are saying. MATLAB does have a for loop. Sure it doesn't use a { and the } is replaced by "end" and the way your specify the iterator is different, but it still has one. Different languages have different syntax - that's just the way it is, not just for MATLAB but for all languages.
  11 Comments
Image Analyst
Image Analyst on 25 Jan 2014
Well it looks like we're done here, but I don't think you illustrated your point about how C is easy but MATLAB is harder. You gave us no code examples to compare them.
Hamid
Hamid on 25 Jan 2014
Edited: Hamid on 25 Jan 2014
In general, problem of MATLAB is in for loops that cause some slowness. If while loops are used instead of for loops, speed will be increased very much (some complicated tests can be very interesting) and therefore, MATLAB, will be an excellent friend for a programmer with very complicated mathematical calculations and operations. Additionally, because of existence of MATLAB Coder toolbox, it's unnecessary to follow C++ for these complicated calculations. In fact, in early future, C++ with respect to MATLAB, will be like Assembly with respect to C++. Only MATLAB. Thanks God for such a powerful software and I wish God's attentions and helps for its kind engineers.

Sign in to comment.


Azzi Abdelmalek
Azzi Abdelmalek on 12 Jan 2014
Edited: Azzi Abdelmalek on 12 Jan 2014
Each language has its advantages and disadvantages, but sometimes, if the user doesn't know how to use it, doesn't mean the language is bad. In your case maybe, if you give an example, there should be a good way to handle it either with c++ or with matlab
  1 Comment
Hamid
Hamid on 13 Jan 2014
I love matlab; it's excellent but syntax isn't in question at all. suppose we want to detect numbers holding in relation: a^2=b^2+c^2 from 1 to 1000 by three consecutive while or for loops. after detecting some elements, we should reject detected elements. one way is inserting zero for them (we use an if statement before executing inner for or while loop for rejecting detected elements). this work, takes very long time even by using mex-file correspondent but if we could say, after detecting first three elements, to loop that we determined these three numbers and go directly to first for or while loop to start from beginning, it takes very smaller time. I love matlab but it is not good in some loops and optimizing for and wile loops, will answer very people that, for example, say that matlab isn't suitable for performing very complicated mathematical expressions involved in physical chemistry that last days, months or even years. I wish that day, performing all my complicated mathematical calculations in matlab.

Sign in to comment.

Categories

Find more on Introduction to Installation and Licensing 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!