Is there AndAlso equivalent for Matlab? - matlab

I need to check validity of an expression and if it was true then check 2nd exp.
It can be written in 2 if-end structures but I want to put condition in conditional breakpoint, and I think it is not possible to write 2 if in one line.
But AndAlso can solve my problem.
any idea?

If you use the shortcut AND, i.e. &&, the second statement is only evaluated if the first one was true. Thus, something like
i>1 && foo(i)==3
should do the trick.

Related

Can anyone pls explain this ahk script logics/commands

Can anyone pls tell what is the purpose of two sequential commas and then 1 in the below given ahk script?
Pause:: Suspend
Pause,,1
return
If the script is suspended you can't unpause with that very same button because the hotkey is disabled.
In that case you need to use the OperateOnUnderlyingThread in the Pause command parameters:
Pause,,1 makes a single button (in this case the button Pause or Break) work as both pause and unpause. It allows the Pause command to run a second time (i.e. to unpause).
Pause::
Suspend ; disables or enables all or selected hotkeys and hotstrings.
Pause,,1
return
It indicates that the first parameter is blank.
https://lexikos.github.io/v1/docs/Language.htm#commands
The comma separating the command name from its parameters is optional, except in the following cases:
When it's necessary to prevent the line from being interpreted as a legacy assignment or assignment expression.
MsgBox, := This would be an assignment without the comma.
When the first parameter is blank.
MsgBox,, Second, Third
From https://www.autohotkey.com/docs/commands/Pause.htm :
Pause [, OnOffToggle, OperateOnUnderlyingThread]
OnOffToggle
If blank or omitted, it defaults to Toggle. [...]
Pause,,1 is the same as Pause,Toggle,1
I think I got the answer.
Two commas mean there is a blank value, which in ahk means 'Off'. In other words it'd be perhaps same if it were: Pause, Off, 1
And 1 means on. That means, it is equal to
Pause, Off, On
I'm only 95% sure of the above.

Eclipse breakpoint conditional skipping

I read several posts on this but I could not fix my problem which is that eclipse skips a conditional I defined on a variable.
if(currentContent=="content") {
return true;
}
Can you please advice what I should do for the conditional to trigger the breakpoint when the value of my string variable is equal "content".
You can't rely on == with Strings. Use .equals().
nitind's point about using .equals is important, but I think a bigger issue is that the breakpoint condition is evaluated BEFORE the line executes, not after. I get the feeling you want to hit the breakpoint when the resulting value of "currentContent" matches your expectations AFTER the assignment, not before.
In this case, I suggest you move your breakpoint to the executable line that comes after this line.

Difference between "IfWinActive" and "If WinActive()"

Can anybody explain the difference between IfWinActive and If WinActive()? I'm really wondering, but Google and official AutoHotkey docs says nothing about.
If IfWinActive evaluates to True, the next line of code (or brace-bracketed code block) is performed, or if False, it is skipped. All it does is evaluate to True or False.
The function WinActive() returns the Unique ID (HWND) of the active window if it matches the specified criteria. If it does not, the function returns 0. Since all non-zero numbers are seen as "true", the statement If WinActive("WinTitle") is true whenever "WinTitle" is active, and then acts just like IfWinActive WinTitle. Note the quotes in the function, but not the directive.

Natural language processing / commands (prolog)

I want to create a predicate, which recognizes a word (in this case: "save") and starts saving the next words, until the sign/word "end" comes.
It should work like this:
?- save.
one
two
end
true.
The predicate for saving:
save(X) :- assert(listitem(X)).
and then I started like this:
save :- read(save).
read:- X -> save(X).
end --> 'end'.
The problem is, that I can add as much words as I want, but if I want to stop the command with "end", the program fails and actually the words have not been saved.
What part of the predicate is wrong? I'd be very happy for some help.
Thank you in advance!
This is some extremely confused code. Here's what you wanted:
:- dynamic listitem/1.
readline(Line) :-
% this is an SWI extension, but it's very handy
read_line_to_codes(user, Codes),
atom_codes(Line, Codes).
save :-
readline(X),
(X \= end -> (assertz(listitem(X)), save)
; true).
Odds are good, somewhere in the code you didn't bring, all you were missing was the effect of the ; true there: that when you find end, you're finished, but not that you failed. But you have a lot of problems here.
save/0 calls read/1, which is a system predicate. All this is going to do is read a word from the user (ending with a period!) and notice that it isn't the word "save". Unfortunately, reading a whole line without periods at the end is a somewhat non-trivial task in Prolog, hence the pile of code in my solution.
read/0 is not called by anything.
The syntax X -> save(X) is almost certainly not what you want. This is the first occurrence of X in the predicate, and so it probably isn't doing you much good to test it conditionally before it has a value.
end --> 'end'. is a DCG rule, but you aren't using phrase/2 anywhere to invoke it (nor are you using end/2 directly with a difference list).
assert/1 is a really bad habit to get into. The ISO predicates asserta/1 and assertz/1 are not only portable, they also give the reader a better idea what the effect on the fact database will be.
Similarly, you have no dynamic declaration for listitem/1, which would raise portability and improve readability.
I would use a 'state machine' approach: it's so simple!
:- dynamic listitem/1.
loop(Mode) :- read(W), loop(Mode, W).
loop(_, stop).
loop(skip, save) :- loop(save).
loop(skip, _) :- loop(skip).
loop(save, W) :- assertz(listitem(W)), loop(save).
test:
1 ?- loop(skip).
|: asd.
|: save.
|: ok.
|: ok1.
|: stop.
true
.
2 ?- listing(listitem).
:- dynamic stackoverflow:listitem/1.
stackoverflow:listitem(ok).
stackoverflow:listitem(ok1).
true.

Jump command in MATLAB

I'm working with the m-file editor of MATLAB and I need to jump from one line to another.
If I need to jump from inside a For...end, I can't use the usual "while"
technique.
Is there anyway to jump from a line to another, like goto in C?
There is no goto statement in MATLAB, but there are a few other commands for use with loops that may help you:
continue: This statement will skip the remaining commands in a for or while loop and move on to the next iteration.
break: This statement will terminate execution of a for or while loop.
There is no goto in matlab. However, this does not say you cannot structure your code to use an {if, else, elseif, end} structural form for your code. Or use a {switch, case, end} form. Or call a function (or subfunction or nested function) to solve your problem. Or use a continue/break to structure your code. One can always solve these problems using one of the existing forms of flow control available.
The use of functions can improve your code in other ways, often by making it more modular, and therefore easier to debug and write.
that solves the problem easily:
caseno = input('input your case no');
switch (caseno)
case 1
disp('this first section will run');
case 2
disp('this second section will run');
otherwise
disp('wrong case no');
end
for j = 1: 1: 24
% LABEL start
a = a + j;
if a > 10
goto('start') % If condition satisfied goto label start
return
else
a = a + 1;
end
end