How to integrate matlab with QT - qt

I want to call matlab from QT 4 (used for UI only in my project) where i can pass values and read values back from matlab. and also run the .m scripts and then get the results back from matlab.

QT is irrelevant here.
You basically want to use the Matlab Engine. You can call Matlab from compiled C++ (for example). You'll probably want to use engOpen to start the connection and then engEvalString to run scripts. You may also want to use engGetVariable, mxGetClassID and mxGetDimensions to access the results.
But definitely read the documentation and try it, then come back with more detailed questions.

Related

How to create a SlotOfQImage in QT Rust?

I'm trying to define a custom QT Slot/Signal for passing a QImage.
I'm using qt_widgets crate which has many predefined slot types like SlotOfQIcon. However it doesn't have one for QImage. I've looked at the source code which is generated with this tool: https://github.com/rust-qt/ritual.
Is it possible to do this in regular Rust project without running complex multistage build involving code generation?
List of implemented slots for reference:
https://docs.rs/qt_widgets/0.3.0/x86_64-pc-windows-msvc/qt_widgets/
I've tried to copy paste generated code for other widgets and modify it, but it doesn't look like a right approach. I don't want to regenerate the whole library just for this case. Are there any simpler options?

how to manage an R program where the functions are stored in different source files [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 6 years ago.
Improve this question
I finally arrived at a point in using R where my programs are not anymore grown-up command line scripts, but real codes. At this point, I think it doesn't make sense to keep all the functions used by the main code in the same source file. Now, If I understand correctly, the way to use function myfunction, stored in file hereliesfunction.r, from a script stored in file myscript.r, is to add the line
source("hereliesfunction.r")
in file myscript.r, before the part of the script code where myfunction is used.
Is this the right approach in R?
Do I need a different source command for each function used by my main code? I guess it works "recursively",i.e., I can put source commands in
hereliesfunction.r to let myfunction use other functions.
What happens when I return from myfunction? Do these other
functions remain in memory, ready to be accessed by the main code too, or are they destroyed just like any other object created by myfunction?
Finally, is there some guideline on whether to store all the
functions used by a main code in the same directory as the main
code, or not?
Once you source a R file, it runs all the commands in that file. If it contains a function definition, it stores it into the global environment and is at your disposal until you remove it or close R session (so 3., yes).
Your entire post is screaming R package. As #docendodiscimus has pointed out, you should invest some time to develop a package. Not only does it hold your code in one place, is easy to maintain, it also offers a great platform to document your code (probably the most important part of code development/analysis) through help files and vignettes and offers easy version control through local and remote repositories (git, svn...).
[about sourcing] Is this the right approach in R?
Yes but in the mid-term, consider building a package as stated by #docendo discimus. devtools::create() and if you use RStudio Projects > New package are your friends. Learning to build packages is made simple by Hadley's R-pkg and was, personally, the best investment ever in R. Plus documenting and writing tutorials/vignettes and writing tests is always useful: it may be time consuming at the first glance, but you will probably soon hugely benefit from it (better understanding of your code, realizing you can improve the package architecture, etc.)
Do I need a different source command for each function used by my main code?
All functions, and in a larger extent code, located in the file sourced will be executed in R (so functions will be declared and available, you can check it with ls()
I guess it work "recursively",i.e., I can put source commands in hereliesfunction.r to let myfunction use other functions.
Yes
What happens when I return from myfunction? Do these other functions remain in memory, ready to be accessed by the main code too, or are they destroyed just like any other object created by myfunction?
Not sure to understand but may be related to previous points.
Finally, is there some guideline on whether to store all the functions used by a main code in the same directory as the main code, or not?
You can store them wherever you want, as long as the path for source is the right one. But it's generally a better practice to store all your functions in the same directory (or in a subfolder, eg /code, so that you just change your working directory once (or if you use RStudio's projects, you don't even need to bother, you just open the project), and as a side effect, as long as one is working in the same directory, the relative paths will still work. And thus you can share the folder with Dropbox or other, which ease collaboration.
Again, in the mid term or if many projects use the same source files, it's probably a good idea to write a package (for your own use, or to share on GitHub or CRAN or...)

Ada dependency graph

I need to create a dependency graph for a software suite that I am working on. In the past the company I work for has always done this manually, but I am guessing that there is a tool somewhere that will do what we need.
The software I am working with is Ada95, and has about 200 code modules/files, with about 40 packages. I need to create a map that will trace every output, individually, back to each input or constant that will have an impact on the output. Does anybody know of a tool that would accomplish this? Or even just partially accomplish it?
AdaCore's GPS (available from http://libre.adacore.com) comes with a command line tool named gnatinspect. You can use this tool to load all cross-reference information generated by the compiler (assuming you are compiling with GNAT). This creates a sqlite database (gnatinspect.db) which contains all information you need. gnatinspect itself provides a number of pre-made queries that might get you at least partially to where you want to go.
You could also look at ASIS, as a way to do this kind of queries directly on the code. I am told this is not so easy to use the first time around though.
There is also an older tool provided with gnat (gnatxref) which does something similar, although it is being superceded by gnatinspect.
Finally, you could look at gnat2xml as an alternative to ASIS if you are more comfortable parsing XML files.

R JIT compiler - is there a way to automatically pre-compile all functions in a script? (for use with shiny)

Is there a way to get R to precompile all functions in a script?
The reason it matters is because the script is code for rshiny. I'd like to push forward the byte compiling to occur when the server starts up rather when the user is requesting a page.
I know cmpfun() could be used to compile one function at a time and modify function calls accordingly, but I'd like to do this without maintaining the extra boilerplate code if it's possible.
You should be able to use the JIT from compiler with:
library(compiler)
enableJIT(3)
or set the environment variable R_ENABLE_JIT to non-negative (3 is the highest amount of compilation). I did a quick experiment with my Shiny app and this seemed to produce no benefit at all, so maybe something is not working correctly. This page provides a few more details on R compilation options.

R statistics console in QT

I am planning to link a Qt project against R to provide some statistical funcionality. I thought it might be quite cute to add some generality to the project by having an R console as a Qt widget within the tab to allow me to do analyses that I haven't thought of in the design stage later on. I was wondering whether it is something that might be accomplished fairly easily?
In particular I'm stuck on how I would access the RTerm from QT? Has anyone else attempted something similar or can give some hints on where to start?
One of the examples for RInside does something pretty close---in around 200 lines most of which deal with the other GUI aspects, it wraps R functionality inside a Qt application.
The example implements a GUI density slider, and the edit box allows you to write an almost arbitrary R expression, or rather the parts that are then passed into an evaluation to generate random number: rnorm(50), or for a mixture c(rnorm(50), rt(50)) etc. You could possibly build on top of that.
See this blog post for more.
Check out Carson Farmer's work on manageR:
http://www.ftools.ca/manageR/
this is a plugin for Quantum GIS (mapping package) that interfaces it to R, giving you exactly what you want - an R console wrapped in a Qt4 body - as well as data transfer between Qgis and R. It handles plots as well.
I've tried to encourage Carson to produce a standalone R Gui project from this code, but he's a busy guy. Aren't we all?
RStudio is largely written using QT, you should be able to have a look at their code and build something similar into your Qt based application:
https://github.com/rstudio/rstudio

Resources