I'm currently trying to compile a Matlab function into an exe file and I'm having trouble to get rid on the Inputdlg part.
The original Matlab code is :
prompt={'Charge équivalente TNT :','X foyer :','Y foyer :','Z foyer :'};
title='Données';
answer=inputdlg(prompt,title);
Wcharge = str2double(answer{1});
Xfoyer = str2double(answer{2});
Yfoyer = str2double(answer{3});
Zfoyer = str2double(answer{4});
valide1 = ~ isempty(Wcharge) && Wcharge>0 && isnumeric(Wcharge);
valide2 = ~ isempty(Xfoyer) && isnumeric(Xfoyer);
valide3 = ~ isempty(Yfoyer) && isnumeric(Yfoyer);
valide4 = ~ isempty(Zfoyer) && isnumeric(Zfoyer);
check = valide1 + valide2 +valide3 + valide4;
if check < 4
disp('Données incorrectes')
return
else
end
As you now I need to get rid of the curly brackets to compile this code and I can't find an alternative to prompt={'Charge équivalente TNT :','X foyer :','Y foyer :','Z foyer :'};.
Do you have any suggestion on how to proceed ?
Related
I used the clibgen.generateLibraryDefinition to generate the Matlab interface for C++ libraries.
I applied it in a Matlab function and it worked well.
However, when I tried to use it in the Matlab Simulink with the Matlab function block, it gave errors " Attempt to extract field 'i' from 'mxArray'. "
Is that anything I'm missing to add in the Simulink?
Thanks!
function cube = fcn(size_x, size_y, range_x_min, range_x_max, ...
range_y_min, range_y_max, power, ...
transmitter_height, receiver_height, ...
transmitter_position, frequency)
coder.extrinsic('clib.Wave.Wave.EMWave');
coder.extrinsic('clib.Wave.Wave.Index');
coder.extrinsic('clib.Wave.Wave.Vec2d');
coder.extrinsic('clib.Wave.Wave.Terrain');
coder.extrinsic('clib.Wave.Wave.Transimtter');
coder.extrinsic('clib.Wave.Wave.Source');
coder.extrinsic('clib.Wave.Wave.Cube');
coder.extrinsic('clib.Wave.Wave.Terrain');
coder.extrinsic('clib.Wave.Wave.Ray');
index = clib.Wave.Wave.Index;
radio_wave = clib.Wave.Wave.EMWave;
terrain = clib.Wave.Wave.Terrain(200,200,range_x_min,range_y_min,range_x_max,range_y_max);
index.i = 1;
index.j = 1;
% radio_wave.transmitter.set_power(1000);
% radio_wave.transmitter.set_height(150.0);
% radio_wave.transmitter.set_number_of_discrete_rays(7200);
%code.varsize('cube',[1 size_x],[1 size_y]);
cube = zeros(200,200);
end
I am working with R and C++. I am trying to include C++ in R , I have the following code:
install.packages('inline')
install.packages('Rcpp')
install.packages('rstan')
library('inline')
library('Rcpp')
library('rstan')
### # start with pure C/C++ function and assign the source code to
### # a variable which we call here includesrc
includesrc <- '
int fibonacci(const int x){
if (x == 0) return(0);
if (x == 1) return(1);
return fibonacci(x-1) + fibonacci(x-2);
}'
### # define the body of the C/C++ program
fibCppBody <- '
int x = Rcpp::as<int>(xs);
return Rcpp::wrap( fibonacci(x) );'
### # pass the above C/C++ function as an argument
### # to cxxfunction()
fibRcpp <- inline::cxxfunction(sig = signature(xs = "int"),
plugin = "Rcpp",
incl = includesrc,
body = fibCppBody)
sapply(1:10, fibRcpp, USE.NAMES = FALSE)
I ran this code which is supposed to include C++ code in R function , it is supposed to run (it is an example from here but it's not working for me.
And I got this error:
Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) :
Warning message:In system(cmd) : 'make' not found
Any idea? Thanks
I'm working with pull review and asks me to factor the following code, someone can help me with this?
#start_time = (params[:start_time].to_time.hour.to_i < #room.opening_time.hour.to_i)? #room.opening_time.hour_minutes : params[:start_time]
#end_time = (params[:end_time].to_time.hour.to_i > #room.closing_time.hour.to_i)? #room.closing_time.hour_minutes : params[:end_time]
To start you could throw some of the crazy long chains you're comparing into variables like so
opening_time = #room.opening_time.hour.to_i
closing_time = #room.closing_time.hour.to_i
starting_time = params[:start_time].to_time.hour.to_i
ending_time = params[:end_time].to_time.hour.to_i
open_minutes = #room.opening_time.hour_minutes
close_minutes = #room.closing_time.hour_minutes
Then you can do
#start_time = starting_time < opening_time ? start_minutes : params[:start_time]
#end_time = ending_time > closing_time ? end_minutes : params[end_time]
Which is a lot more readable.
From there I would recommend extracting out to two methods to run the actual conditionals, to make it clearer in English what the code is trying to do. For example:
def get_start_time(time)
starting_time = time.to_time.hour.to_i
opening_time = #room.opening_time.hour.to_i
open_minutes = #room.opening_time.hour_minutes
starting_time < opening_time ? start_minutes : time
end
def get_end_time(time)
ending_time = time.to_time.hour.to_i
closing_time = #room.closing_time.hour.to_i
close_minutes = #room.closing_time.hour_minutes
ending_time > closing_time ? end_minutes : time
end
#start_time = get_start_time(params[:start_time])
#end_time = get_end_time(params[:end_time])
Which, while it may be more physical code, is a lot clearer and simpler to read, which is a huge part of refactoring, especially when working with a group.
I'm trying to run the following code as a sahi script:
_include("initialScript.sah");
_include("secondScript.sah");
function currentTime(){
var $current = new Date();
var $hours = $current.getHours();
var $minutes = $current.getMinutes();
if ($minutes < 10){
$minutes = "0" + minutes;
}
if($hours > 11){
_log("It is " + $hours + ":" + $minutes + " PM");
}
else {
_log("It is " + $hours + ":" + $minutes + " AM");
}
if($hours >= 8 || $hours =< 20) {
_include("aScript.sah");
_include("anotherScript.sah");
...
}
else {
//do nothing and continue below
}
}
_include("yetMoreScripts.sah");
...
Simply put, I have a block of various scripts, followed by a check of the current time.
If it isn't between 8am and 8pm, the included block of scripts is skipped and the others below are executed. The _logs tell me that getting the time appears to work as intended.
Yet whenever I attempt to run the script as is, I get an immediate failure and completely unrelated Syntax Errors (such as on an _include way further down that is not faulty at all). Taking the _includes out of the if Statement seems to make the errors stop. For all I know this should work but just doesn't. Does anybody have experience with something similar and could give me a hint as to where I made a mistake?
as far as I can tell, this should work. A simple test:
test1.sah:
_log("ok");
test2.sah:
if (true) {
_include("test1.sah");
}
When I run this from the Sahi Controller, I get an "ok" logged. Maybe recreate this test and check if you get the same results.
Maybe it's the ";" missing after your includes?
Are you passing dynamic values to include? like _include($path)?
I'm writing some code that utilizes the boost filesystem library. Here is an excerpt of my code:
artist = (this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) ? (*(paths_iterator->parent_path().end() - 1)) : (*(paths_iterator->parent_path().end() - 2));
album = (this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) ? "" : (*(paths_iterator->parent_path().end() - 1));
Types:
artist and album are of type std::string
this->find_diff returns an int
this->m_input_path is a std::string
paths_iterator is of type std::vector(open bracket)boost::filesystem::path>::iterator
I get a compile error:
error C2039: 'advance' : is not a member of 'boost::filesystem::basic_path<String,Traits>::iterator' d:\development\libraries\boost\boost\iterator\iterator_facade.hpp on line 546
This code is part of a program that outputs a batch script that uses lame.exe to convert files into mp3s.
The music library this is designed for has the format:
root/artist/song
OR
root/artist/album/song
this->m_input_path is the path to root.
I'm not sure if I'm approaching the problem properly. If I am, how do I fix the error that I am getting?
EDIT:
My code is now:
boost::filesystem::path::iterator end_path_itr = paths_iterator->parent_path().end();
if(this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) /* For cases where: /root/artist/song */
{
album = "";
end_path_itr--;
artist = *end_path_itr;
}
else /* For cases where: /root/artist/album/song */
{
end_path_itr--;
album = *end_path_itr;
end_path_itr--; <-- Crash Here
artist = *end_path_itr;
}
The error that I now get is:
Assertion failed: itr.m_pos && "basic_path::iterator decrement pat begin()", file ... boost\filesystem\path.hpp, line 1444
basic_path::iterator is a bidirectional iterator. So arithmetic with -1 and -2 is not allowed. Operators + and - between an iterator and an integer value is defined for a RandomAccessIterator.
Instead of using .end()-1, you could resort to using --.
Your new error indicates that your end_path_iter doesn't have enough elements (should that be "decrement past begin"?), i.e. your path is shorter than you expect.