Unnecessary error in matlab - matlab

I have this error in matlab editor showing
an end might be possibly missing matching for
The code runs fine though, I am not sure why it is showing this error even when everything is matching. Any idea guys why this is so and how to remove this annoying red marker?

This is not an error, it's a mlint warning which should help you writing good code. In your case, the if and the end are not indented at the same level. Click on the if to see which end is matching.

Related

Auto fixing warnings reported by ScalaStyle

Is there a way to get ScalaStyle (or any other automation tool) to fix some of the warnings it finds?
For example --
Line contains a tab (shock!!)
There should be a space before the plus (+) sign
File must end with newline character
At a stretch
Public method must have explicit type
As of right now, Scalastyle does not have a way to automatically fix errors. However, it looks like Scalafix might. This is from their documentation:
A scalafix “Rule” can report lint messages and provide auto-fix patches to violations of some kind of rule/coding style/convention/breaking change.
Sounds promising! I have not had a chance to use it yet, but since this question has gotten no replies in almost three years, it seemed worth adding this as a possible solution to your problem if anyone else has a similar issue.

What's wrong with brainfuck on ideone?

Clearly, there is something wrong with my understanding of brainfuck, or there's something wrong with bf interpreter on ideone.com.
By entering code as simple as ,.,. (reads two characters and prints them), I get an error "bff: out of memory (871638280)" . Why do I get this ?
NOTE: The true problem is that I'm trying to solve a problem on SPOJ, and some code that works on brainfuck interpreters that I found across the internet, doesn't work on SPOJ and ideone.com.
It appears to work fine, my BF torture test runs properly.
ideone.com 9fQ2Ej
I am NOT going to try to fight this UI to make the BF look correct!
It's here:
https://github.com/rdebath/Brainfuck/blob/master/bitwidth.b
It does appear to have a large cells size though and isn't fast enough to offset this.
EDIT: (No newlines below Grrr)
Anyway Daniel Christofani's end test:
,>+++++++++,>+++++++++++[<++++++<++++++<+>>>-]<<.>.<<-.>.>.<<.
Gives 'LA' showing that the program accepts input successfully, gives the correct character for newline and gives '-1' for end of file. As it's a big cell interpreter this is perfectly acceptable.
HOWEVER; I do see your point, there's something weird going on I suggest you try one of the javaScript implementations. They run in your browser.
http://t-monster.com/apps/brainfuck_IDE
http://www.iwriteiam.nl/Ha_bf_online.html
http://brainfuck.devbar.de/

Tips on optimizing this code that loads multiple files in Matlab?

fname = dir('*sir');
dayH = zeros(length(fname),1360,3600);
for i=1:length(fname)
dayH(i,:,:) = loadsir(fname(i).name);
end
fname = dir('*sir');
dayH = cell(1,length(fname));
for i=1:2
dayH{i} = loadsir(fname(i).name);
end
Basically it loads all my files. I have a separate .m file called loadsir that loads those specialized files. The output of the .sir files will be an array 1360x3600.
Right now that code is crashing saying, "Cannot display summaries of variables with more than 524288 elements." I guess it's because 1360X3600 = 5,000,000 about?
Putting Serg's comment as an answer:
Most likely you missed a semicolon (;) somewhere in loadsir. Matlab then thinks you want to print the output, which it won't do due to the large number of elements.
Additionally, to prevent such things from happening in the future:
Matlab is an interpreted language, meaning, no compilation is necessary. Any and all code can be parsed while you type it, which allows for things like auto-correct. Of course, this sort of thing is included already in standard Matlab. If you don't already, code in Matlab's own editor every now and then. It warns you of such silly mistakes/errors (and a lot more), including but not limited to, via the right vertical bar in the editor. The little square at the top right of the window should always be green. If it's orange or red, there's things to be improved or corrected, respectively.
The right vertical bar is an overview of all the lines in your file that leave room for improvement. If a small orange/red bar appears somewhere, a mouseover will tell you what's wrong with what line. Clicking it will navigate the editor to the line, which will likely be wavy-underlined in either orange or red. Mouse-over the line often gives useful suggestions, and <alt>+<enter> is often enough to fix the simple mistakes. I find it an indispensable tool when developing larger applications in Matlab.
You can of course configure which errors/warnings this tool ("code analyzer", formerly "mlint") displays. Sometimes, there will be a warning about an inefficiency that you simply cannot work around. Add an OK-directive behind the line to suppress it (%#ok), but don't make a habit of suppressing anything and everything "annoying" because that will of course completely beat the purpose of the code analyzer :)

Can indenting affect Matlab code?

Is this possible? It shouldn't be but sometimes its behavior is quite against ordinary programming sense.
No, Matlab isn't affected by indentation.
They do have editors that will automatically indent the code for you, but it is for readability purposes only. Keeping your code readable with smart-indenting is always a good idea not only for yourself, but for others who may have to read through your code.
Note: Warnings can occur (depending on the IDE) if the indentation isn't consistent, but even sporadic indentation won't affect how your code executes in Matlab.
It'll give you warnings if you don't indent properly. If you make a if or for loop or something like that and the end block isn't inline with it you'll get a possible warning that says the statement might not be aligned with its end block. CRTL+A CTRL+I is easy enough though.

Comparing Strings Objective C

When I use == to compare the strings it works on all but some strings that have a space added... (added with [NSString stringWithFormat:#"%# %#",self.title,collectionName])
But when I compare with isEqualToString, it returns True/YES every time. The comparison in the image goes into the condition and hits the return... Should be impossible for this to hit line 640, but it does.
Can anyone explain this?
There is a ";" after the ")" on line 637 that why it always went into the condition... damn I suck... seems like that would throw an error somehow
If you use the LLVM compiler in Debug project setting, (not quite stable enough for release yet I think), you'll get warnings about issues like the one you had.
In your case it would issue a warning than an "if" statement had an empty body.
Used in conjunction with turning on the static analyzer for every build, you can catch a ton of problems early, especially the stupid ones that are hard to debug because they are so stupid they are easy to overlook (and here I am not criticizing you, as I have made the same mistake countless times!)