How to use variables in Matlab App Designer in all callbacks [closed] - matlab

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have different callbacks in an Matlab App Designer App. In my case several buttons. I need to use the same variables for that.
I only get an error when using a variable I created in one Callback in another...

I think I got your problem.
The easiest way is in beginning to create a new property (red button on the top left in EDITOR) and use it as a variable throughout the code.
Be careful to use app.variablename to address the variable.
If your code is already finished and you just discovered that error, you can set properties for only the variables you need to exchange and then get them like this:
set property:
properties (Access = private)
varone %first variable
vartwo % second variable
...
end
get Data for Exchange:
varone = app.varone; %(now you can use varone instead of app.varone)
make it public again at the end of your callback:
app.varone = varone;

Related

Calling functions from inside (Matlab) code sections [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a massive script consisting of many code sections that I run independently of each other. For some of these code sections, there is a lot of repeating code, and so I wanted to define a function that I can call multiple times from a given code section. However, I am either getting the error "Function definitions are not permitted in this context.", or, once the code execution reaches the function call, it says the function is not defined.
So it seems that Matlab (2016b) does not accept functions to be defined within code sections, or I am doing something else that's wrong.
What I tried:
define the entire script as a function, named exactly as the name of the containing .m file, and with a corresponding 'end' on the very last line
define the function containing my repeating code either at the end of the code section for which it is relevant
.. or at the end of the file (before the top-most function's own 'end')
.. or at the end of the file (after the top-most function's own 'end')
My code organisation might be criticised, e.g. I might instead use multiple functions in my file, rather than script-style code sections. However, I would like to know whether there is a way to be able to call functions from inside code sections.
You need to read the following documentation:
Scripts and functions
Create functions in files
Notably, the second contains the relevant information:
Starting in R2016b, another option for storing functions is to include them at the end of a script file.
You say you're using R2016b, so you can define functions within scripts, but they must be at the end of the file. The documentation contains the following example of a valid script containing functions:
x = 3;
y = 2;
z = perm(x,y)
function p = perm(n,r)
p = fact(n)*fact(n-r);
end
function f = fact(n)
f = prod(1:n);
end

e4 selectionservice - list or single object and adapters [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a question regarding "best practice" on the e4 selectionservice
1) Handling single and multiple selection
E.g on a tableviewer I can select a single or multiple elements. Depending on that, my active selection is either a object or a collection of objects.
What is the best practice to handle that in my listener?
....selectionService.setSelection(structuredSelection.getFirstElement())
OR
....selectionService.setSelection(structuredSelection.asList())
public void xy (#Optional #Named(IServiceConstants.ACTIVE_SELECTION)
List selection){} --> selection is null if a single element is selected
OR
public void xyz (#Optional #Named(IServiceConstants.ACTIVE_SELECTION) MyObject selection){} --> selection is null if multiple elements are selected
Do I need to implement both methods to handle both scenarios? Why is a single element not packed in a list or vice versa?
2)
How to handle active selections that can be adapted to a target Object?
Do I need to have ISelection parameter and check for the adaptation manually or is there any way the framework can adapt and inject if possible?
Thanks a lot in advance
The normal selection is the actual IStructuredSelection object, not its contents:
selectionService.setSelection(structuredSelection);
public void xx(#Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection)
So you only have one method and it receives all types of selection.
For adaptable objects there is nothing that will do this automatically. Use the org.eclipse.core.runtime.Adapters class to adapt an object:
IFile file = Adapters.adapt(object, IFile.class);

My Xcode is not recognizing a struct variables [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am building a example project with sections using a TableView with this video:
https://www.youtube.com/watch?v=zFMSovtqqUc
When this boy explain exactly at 2 minutes and 55 seconds a list of the variables created in the struct should appear in the list, but it does not.
Can someone help me to understand what I am doing wrong?
Attached a print screen of my Xcode displaying the values where the list of value explained in the video should appear.
I am just a beginner following some video to learn to code.
Thank you very much for your time, I really appreciate it!
The same it's happening to me, look
If for you it's a big problem you can put 2 parenthesis around the value you are creating
This seems to fix the problem.
Conventions
Sorry but I could not avoid this
Objects is a wrong name for a struct (intact struct values are NOT objects)
Implicit unwrapped optionals (like the property of the struct into the example) are dangerous
Variable names should begin with a lowercase char
In Swift we don't put the name of the type of the variable inside the name of the variable.
The variables aren't recognised when there is a ] automatically provided when you type in [ like this:
If you delete the ] as soon as it appears when you type in [, the error is fixed, like so:

Attempt to execute a script as a function [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
There is a script I have been trying to run and the error it produces is
Attempt to execute SCRIPT Master_nusery_algorithm as a function
Any ideas with how I can solve this.
Here is a copy of the script
mangnursery = mangrovenurseries(map,mangrovefringe,40,20,500,830);
You need to have a proper function definition at the top of the file. This is a good readme: http://www.mathworks.com/help/matlab/matlab_prog/scripts-and-functions.html
Specifically, try something like this at the top of your mangrovenurseries function:
function mangnursery = mangrovenurseries(map,mangrovefringe,param1, param2, param3, param4)

Compile error when setting class in VBA [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I copied code from here but I'm getting an error when trying to run the code.
The problem would be in:
Public NextItem As New queueItem
and the error message is:
user-defined type not defined
Is my VBA version not right to do this or am I doing something wrong?
You probably mean this link? The one you provided has the alternative implementation (with arrays, not with references).
I got it to work for me. Steps:
Right click on the VBA project file name, and go to Insert-> Class Module:
Click F4. The Properties window appears. Then go to the class Name and change it to Queue:
Copy and Paste the Queue Class code you found at the web site. Repeat the previous and this step for the QueueItem class (i.e., insert a Class Module, name it QueueItem and copy the code inside that class module).
This time, insert a Module using the same process (not a Class Module, but rather a simple Module). You do not need to give your module a name, Module1 will be OK.
Copy the Sub TestQueue() inside the module and run it. It should work. If you use Option Explicit on your module, you will get an error that element is undefined. So we need to define it: Dim element as Variant, under the first few Dim statements of the subroutine. Then it should run.
The above worked for me, let me know if I can be more precise, or send the file to you.