for loop like c++ in MATLAB
显示 更早的评论
for loop in C or C++ is very flexible and fast. Why MATLAB doesn't create a for loop like C or C++?
回答(2 个)
Image Analyst
2014-1-12
1 个投票
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 个评论
I am not sure I understand what you mean. That being said, I like Matlab, but it can be rather sluggish. It's the price you pay (besides what the Mathworks charges) for a high-level language. Also, it is an interpreted language, so there's an overhead right there.
If you write decent C++, then Matlab is not going to beat that.
The question remains whether you can write fast code in another language and you are willing to invest the time it takes. You might have to go down to assembly if you want blazing fast, but then you have to be confident that you can do a better job than an optimizing compiler.
Image Analyst
2014-1-13
I don't see how a^2=b^2+c^2 is going to take 3 loops. Two maybe, if you want every possible combination of every b with every c, but how do you get three? What is being incremented in each loop?
Hamid
2014-1-15
Sean de Wolski
2014-1-15
Sure. Use:
break
for ii = 1:10
for jj = 1:10
if jj>5
break
end
end
disp([ii jj])
end
Nothing you've described is not readily available and fast in MATLAB.
José-Luis
2014-1-15
Then don't use a for loop. A while statement should do the trick
ii=1;
while ii < 10
ii = ii + 1;
if something
ii = whatever iteration you want to go back to
do stuff
ii = you can even jump forward
end
end
Image Analyst
2014-1-16
I didn't really understand what "we cannot say to first loop anything from third loop" means. I think we're all waiting for you to give us a loop in C and a loop in MATLAB (that does the same thing if you can), and show how what you want to do is much easier in C than in MATLAB.
Hamid
2014-1-25
Image Analyst
2014-1-25
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.
Azzi Abdelmalek
2014-1-12
编辑:Azzi Abdelmalek
2014-1-12
0 个投票
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
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!