MATLAB with some BUGS)
显示 更早的评论
I know MATLAB is one of the powerful tool in many field, I write this question because SO MANY BUGS are makes me crazy.
I use MATLAB 2016a for Image processing and calculating energy resolution about Radiation Detection System. I use webcam class to combine flood images to Real images. But everytime i call webcam instructions supported by MATLAB, MATLAB SHUT DOWN BY ITSELF.
Besides, I build some GUI environments for testing easily. And there are some loops for collecting data. But MATLAB just escapes from loop even i don't use BREAK. I used infinite loops to check this problem. Maybe I think there are some conditions i didn't notice. BUT HE ESCAPES FROM INFINITE LOOPS EVEN I DON'T USE BREAK.
That ridiculous 'Paradigm' breaks my concept of programming. Does anyone suffer from these problems?
17 个评论
Rik
2017-7-11
Try to condense these problems into one or two MWEs (minimally working example). Without that, it is very difficult to distinguish a potentially small coding mistake from a true bug in Matlab. There are staff members watching this forum, so if you show that there really is a bug, I bet they will be very interested.
Adam
2017-7-11
Generally code does what the programmer tells it to. That is not to say there aren't bugs in the language itself, it would be infeasible for there not to be, but I've certainly come across very few in 10 years working in Matlab.
On the flip side I have come across an infinity of cases where I did something wrong that I couldn't work out and was tempted to assign as a bug in Matlab itself until I saw the light and realised what I had done wrong.
Image Analyst
2017-7-11
编辑:John Kelly
2017-11-10
It happens, and the more you deal with low level things like hardware drivers and DLLs, the more likely it is to happen, though all large software packages will have bugs. I guess YeeHang thinks every single package of commercial software stinks then.
@YeeHang Kim: Please note that the purpose of this forum is to solve Matlab problems. The current text of your question does not allow for assisting you in solving the problem, but you try to share your emotions only. Then I recommend not to invest too many emotions, because Matlab is a programing language only. If you are happier with another tool, simply switch.
Elias Salomão Helou Neto
2017-9-18
I agree with Jan simon: switch. Matlab language is old and should not be used anymore. It features several pre-built algorithms and numerical methods, but most of them are based on freely available sotware library.
I switched to Python, and now I know that only people who refuse to use other tools are still stuck with Matlab. Switching is indeed the way to go. Next I will try Julia instead of Python.
For low level tasks I use C/C++. Then I can call C/C++ routines from Python without having to write a single line of Python-aware C/C++ code. It is amazing, when using Matlab you will need to write mex files, which are nonsense as every single decent programming language in the world should allow you to call C (at least, but C++ should also be possible) directly. For the simple reason that there are thousands of very good C libraries. Ah, FORTRAN is callable too.
So, don't use Matlab: it is slow, a bad programming language, expensive, closed source (scientists that use closed source software have no commitment to reproducibility). It is doomed to extintion. If you are one of those people that simply cannot bear the effort of learning a new programming language, I feel sorry for you, but at least give Octave a try, it is free and open source and the language is very similar to Matlab, almost identical but slightly improved.
Walter Roberson
2017-9-18
I can't help but notice that Java cannot call C directly, only through jni which requires the C to be specially structured. Though admittedly some people do say that Java is not a decent language.
Jan
2017-9-18
I did not say "switch", but "if you are happier with another tool, simply switch."
MEX functions are simply small wrapper function, which convert the Matlab arrays to C arrays and back again. Then all C libraries can be used also. This is not "nonsense".
I use many other tools besides Matlab. It is not the point, whether I like Matlab. I tend to like only persons, cats, coffee, music - and solved programming problems. If they are solved by Matlab - fine! If it is Python, Java, Fortran, C, Cobol, Lisp or a drilling machine - fine! The idea is to solve problems, not to use tools. And I'm seriously convinced: You can solve many problems with Matlab.
"doomed to extintion" - well, I assume this will take a while.
Elias Salomão Helou Neto
2017-9-19
Well, Java is not very much used in scientific computing, at least not that I am aware of. Still, it does matters as it is the most popular language aout there, at least according to TIOBE popularity index. Again, I find it very odd since almost no software that I use is written in Java and no numerical analyst I am aware of uses it.
About being doomed to extinction, to my surprise Matlab seems to be still very popular according to TIOBE. It is very surprising to me that proprietary, bad and expensive systems are not all quickly declining these days. In scientific computing for the academia, not having access to source code should be, from my viewpoint, a no-go.
Moreover, I have yet to see what actual numerical problem is to be solved by Matlab more effectively than by some other languages. I don't know about Simulink, but Matlab per se is certainly unnecessary these days.
One reason for its popularity is its strong presence in academia being taught for students. And we know that people who once learn a language tend to get lazy about learning other languages.
I have used several languages, and Matlab's language is by far the worst. Java may be worse, I don't know, I have used very little of it.
If I am to use a language that will call C/C++ code, I will never use Matlab. Because there are more practical, more enjoyable and more smart ways of doing it. In that sense is that I mean that writing mex files is nonsense: you don't have to if you pick the right tool.
Cedric
2017-9-19
编辑:John Kelly
2017-11-10
I've been programming for a good 30 years, and if there is a constant about these discussions, it is that they are completely sterile!
Coming here for saying that MATLAB is bad or worse than X is almost as useful as going on a Python forum for complaining against blocks delimited by the indentation.
Yet, you will observe that if the OP reformulates his "question" in a fashion that enables a productive discussion about debugging and solving his problem, there will always be experienced people here ready to help.
Walter Roberson
2017-9-19
JPL runs Java apparently.
https://www.quora.com/For-scientific-computing-is-Java-useful-in-a-way-that-C-or-Python-arent
@Elias: I you are surprised about the fact, that many people use Matlab, this might be a hint, that it has some power you are not aware of. I does not necessarily mean, that all the Matlab users are lazier or less informed than you.
@Cedric: You hit a point. This discussion will reveal emotions, but does not help to solve problems. "My computer/OS/programming language/kid/car is more epic than yours". Thanks for pointing this out.
Adam
2017-9-19
Matlab has done what I have needed it to for 10 years so I have no need to switch. The language is fine, has some disadvantages compared to others and some advantages. Writing matrix code in C is tedious when I don't need to. I've only seen python code and worked with it on a couple of occasions, but it didn't dazzle me with clarity and brilliance to the extent I felt I must drop Matlab instantly. People just use what gets the job done. Matlab has excellent documentation and I am not too interested in sifting through loads of 3rd party contributions such as open source code can have to decide which I want and which is good enough quality.
We do all our commercial code in C++ or C# though, Matlab is what we use for research and prototyping, for which it serves us well.
If it doesn't serve others well then they should avoid using it. But just making an opinionated pitch to not use one language or another is pointless!
Elias Salomão Helou Neto
2017-9-19
Well, for the sake of clarity, I have used Matlab for decades. The best hing that has ever happened to me as a Matlab user is to have switched.
I am a very skilled programmer, and, again, I have yet to see someone present me a real use case for Matlab. People often say "programming arrays in C is tedious". Great, this is ture, but it is not like the choices are C or Matlab. And even if they were, there are numerous libraries to help the programmer.
What I am doing here is trying to share knowledge. My knowledge, from decades of expertise is: I don't see a real use case for Matlab. If you're as the OP is, just learning a language (he must be a beginner for the post sounds like he is), you should try something free and more modern.
There are a couple of reasons that may seem compelling towards using Matlab. The first and foremost is people not having the time to learn another language. I feel sorry for these people. Using Octave may seem like an option, but it is often much slower than Matlab.
Thus, the fact that Matlab is pushed in academia is, to me, a major reason to keep myself off Matlab. Undergrad students are taught a language that is, to say the least, no better than the free open source options, only to later get stuck to it, or otherwise have to invest a large amount to effort in learning another language. Leave aside the "other language are better" issue, Matlab's marketing is not something I appreciate, to say the least.
Walter Roberson
2017-9-19
I answer a lot of questions here about a wide variety of topics in mathematics, engineering, physics, image processing, and other computing. I can often express the answers in moderately short code, calling upon one of the over 50000 routines that Mathworks has created, instead of having to spend my time researching each of the various routines and writing them out (and debugging debugging debugging.) That is a huge productivity increase when the purpose is to solve the problem.
Adam
2017-9-19
Not everyone is a fan of open source code either. Its supporters are always very vocal, but there are plenty who are happy to just work with a well established and respected product. Open source is not always better just because it is open source. I'm sure I'd find plenty of other languages useful if I learned them, but there is zero requirement for me to do so at the moment when the language I use does the things I want and my company happily pays for it so cost is not relevant to me personally.
I never learned Matlab in academia though. Indeed I never even heard of it before I had to use it in my current job. I'm a C++ programmer by learning. Good documentation is a key factor in a usable tool for me. I need to spend my time researching what I'm researching, not researching tools to help me do it.
The original post just talked about something that will happen in any language - i.e. a user bug that is easier to blame on the language!
Elias Salomão Helou Neto
2017-9-20
Walter, I would love to have concrete examples. I claim that what you say is simply not true, Matlab gives no productivity boost over Python + libraries. I have been there, done that. Much less debugging with Pyhton than with Matlab, is what I have experienced. I too always want to solve problems. That's what we all want to do. No need to use bold letters, to shout or to be passionate.
Adam, Matlab's documentation is indeed reasonably good, but I happen to find very good documentation for Python libraries too. Even though one needs to go online to get it. The fact that the Python community is larger helps a lot too. Every question is already answered somewhere, although I have yet to find unanswered Matlab questions too.
I agree that the problem with the OP is not Matlab specific. Also, Open Source may not be necessary for everything, but it is alwasya good to have freedom, and it is essential in science, for reproducibility purposes. Admitedly, this is a rather utopic matter, as most hardware is proprietary anyway. However, not having to spend thousands of dollars in software is a plus. You know, you can get very good hardware for this money and it can be a major productivity boost.
For the sum of the reasons I have exposed, I believe that it is a good thing for beginners not to start with Matlab, unless they must. If not, Python is a better tool. It is free, it is more advanced as a programming language, it has a huge library of helpers functions, it is less bug prone, it has a larger programming community, it requires less hardware resourcers, it can be run anywhere (even Android and iOS) and so on.
Walter Roberson
2017-9-20
Elias, you can click on my username and look through my over 10000 contributions here to see evidence that I do indeed answer a lot of questions here about a wide variety of topics in mathematics, engineering, physics, image processing, and other computing.
回答(4 个)
I'm absolutely convinced that Matlab does not break out of loops without beeing instructed to do so, never, and under no circumstances. There will be a deterministic reason for exiting the loop. If you post the code, which reproduces the problem, the readers of the forum can help to identify the reason of the behavior, which differs from your expectations.
In opposite to this, the crashes you observe while using the webcam class, sounds like bugs. Can you upgrade to 2017a? Did you send a bug report to MathWorks already? What did they answer? Did you find the problem in the list of reported bugs and do you find a workaround there? Do you get any details about where the code crashs, e.g. in the log files, error messages or from using the debugger?
I do not know any software, which does not contain bugs. The support of MathWorks is much better than the service of the most other software companies. This forum is a marvelous addition. I'm not hapy with the policy to fix bugs by upgrades, because each upgrade contains new features and looses old deprecated ones, and in consequence new bugs are included. In consequence you can write reliable Matlab code by deciding for one release and include many work arounds to cope with the existing bugs. Then upgrading to a newer version becomes more and more horrible. (I'm still running a Matlab 6.5 machine, because I must be able to reproduce the data of publications for 10 years.)
You are right: Matlab contains many bugs. And I love it, because I do not know any other programming language, which has fewer bugs, a greater backward compatibility and a better documentation and support.
PS. I'm not payed by The MathWorks.
[EDITED] A small example for an infinite loop, which is left without a break:
k = 0;
while true
k = k + 1
if k == 10
true = 0;
end
end
You can hide the redefinition of true in an eval or in a subfunction and assignin('Caller') also. There are many other ways to create an unexpetced behavior, but in all cases it is not a problem of the code, but of the expectations.
3 个评论
Guillaume
2017-7-11
because I do not know any other programming language which has fewer bugs. That's a bit controversial! I'm 100% certain that C, C++, fortran and other old fashioned languages have a lot less bugs than matlab for the simple reason that these are overseen by international committees who spend years arguing about each tiny detail to make sure the whole language was consistent. On the other hand, none of these languages evolve as fast as matlab.
@Guillaume: I was not precise enough. While C and C++ are perfect, the compilers are not. E.g. the LCC shipped with older Matlab versions failed for accessing int64_T arrays and many header files missed important symbols. After a high optimization, the numerical results can differ, but it is debatable, if this is a bug or a feature. In consequence it is not enough to publish a C source code, but to be sure that others can reproduce the results exactly, the compiler and the used settings are required.
Another point of view is that a program written in C is much more prone for bugs than a Matlab code. It is trivial to srach the machine in C, but really hard to do this in Matlab. There are many workarounds e.g. safer versions of the string libraries, but it is not trivial to use them, see e.g. https://www.sudo.ws/todd/papers/strlcpy.html. Many implementations work with specific compilers only. I'm faced with functions like strncmpi, _strnicmp, strcmpni depending on the used headers and libraries. A lot of preprocessor directives must consider the versions of compilers, libraries and operating systems. The C++ and C99 comment style let the ANSI C compiler stop with an error, except if you allow these comments by using an input flag during the compilation. Brrrrr. Nevertheless, Matlab changed the output of strncmp(a,b,0) without a note in the documentation also some years ago.
When I try to run some Matlab and C code written in 1999, I expect Matlab to need less adjustments to produce the same results.
There have been a bunch of bugs concerning the end command for indexing in Matlab in the last 20 years. In C there is no such command and you can access x(end+1) freely. So my claim that "Matlab has less bugs" might be a question of taste. A new proposal:
Matlab code is more stable in general compared to other
programming languages.
But the comparison is weak: I can share Matlab code using imresize() easily, while expecting that another user can run some C code I use to resize an image is a completely different story.
John D'Errico
2017-7-11
Yes, but the bugs in question are in a webcam interface. Fortran may have a webcam interface written by some other party, but it will be just as at risk of problems.
John D'Errico
2017-7-11
编辑:John D'Errico
2017-7-11
3 个投票
This is a silly question. Not a question at all, just a rant. Sorry, but that is all. By setting the title as pure flame bait, you are not looking for a constructive answer anyway.
No, I'm not at all surprised. ANY language that tries to deal with hardware interfaces will see lots of bugs. Why? Because hardware changes, CONSTANTLY! And if the hardware stayed fixed, then your OS changes frequently enough that the writers of the package have a hard time keeping up with all changes. Hardware interfaces are a moving target, made more difficult because the platform you are standing on is moving too. Did you change a firewall recently? Install a virus protection tool? For example, I surprised myself when one tool stopped working. No reason at all until I realized I had just made a minor firewall change in something that I thought innocuous, all done because we had replaced our router.
So in all seriousness, yes, I'm sorry, but you can't really be surprised at problems. Use the most recent version, as it may have fixes in it. MATLAB itself is pretty stable. I've not seen a crash in many months, something that is more than I can say for most of the software I use.
Steven Lord
2017-7-11
YeeHang, addressing the two main issues you described separately:
But everytime i call webcam instructions supported by MATLAB, MATLAB SHUT DOWN BY ITSELF.
That sounds like there may be a bug in MATLAB, the webcam driver you're using, both. Or there may be a problem with the OS, a physical problem with the hardware, etc. Doing a search of the Bug Reports for "webcam" in release R2016a I only found two hits, and I'm not sure either is related to the problem you described unless you're using a Microsoft Surface Pro 4 built-in camera.
If you're not using a Microsoft Surface Pro 4 I don't know if it would be possible to debug that crash in this forum, so I recommend contacting Technical Support directly using the Contact Us link in the upper-right corner of this page and work with them to determine the cause of the crash and how to correct it.
But MATLAB just escapes from loop even i don't use BREAK. I used infinite loops to check this problem.
Well ... infinite loops may not be infinite depending on how you wrote them.
while true
% do something
end
That's not going to break unless you call break in the "do something" part of the while loop or press Ctrl-C. [Or kill MATLAB using Task Manager (Windows), KILL (Linux, Mac) or similar tools.]
I just launched 32-bit version of an older release of MATLAB (release R2015a) using the -win32 flag and ran this code. That's a pretty fast-running infinite loop, I think.
>> tic
for k = 1:Inf
end
toc
Warning: FOR loop index is too large. Truncating to 2147483647.
Elapsed time is 3.920841 seconds.
You could try to do the same on a 64-bit version of MATLAB, but it would take substantially longer since the loop index would truncate at intmax('int64') rather than intmax('int32').
Anyway, we can't really diagnose what's going on without seeing a small sample of your code. If you don't want to or can't post it here, I recommend sending it to Technical Support when you contact them about the camera-related crash and ask them for help determining why it terminates earlier than you expected.
Walter Roberson
2017-7-12
1 个投票
I gather that the loop being exited is a data collection loop. Data collection relies upon the remote end supplying correct data in the correct timing. Timeouts are common, as is the remote end sending something unexpected that your code reacts badly to. It is therefore not uncommon for data collection loops to be exited because data was not available or because what was provided triggers errors in the processing. It would be common for an error to be signaled in these cases -- an error that could be caught with a try/catch block and handled more gracefully.
类别
在 帮助中心 和 File Exchange 中查找有关 시작과 종료 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!