Unable to run compiled Matlab code that uses "Presentation" for report generation - matlab

I am trying to convert a simple program that uses "Presentation" (from reportgen package) to a .exe.
The code is as follows:
makePPTCompilable();
import mlreportgen.ppt.*
slides = Presentation('mySlideAddPresentation.pptx');
slide1 = add(slides,'Title and Picture');
plane = Picture(which('tulips.jpg'));
plane.X = '4in';
plane.Y = '4in';
plane.Width = '5in';
plane.Height = '2in';
add(slide1,plane);
close(slides);
I get the following error on running the complied version:
" Undefined function 'Presentation' for input arguments of type 'char'"
Any idea what I am missing here?I am on 2015b, used the following link for help: https://www.mathworks.com/help/rptgen/ug/compile-a-presentation-program.html

You need to make the reportgen compilable, see here and here
In my code I put:
if ismcc || isdeployed
% Make sure DOM is compilable
makeDOMCompilable()
end
Then it compiles fine! :)

Related

Correct parameters for rotation using $BitmapDecoder.GetSoftwareBitmapAsync

I have this PowerShell code:
$AsyncTask = $BitmapDecoder.GetSoftwareBitmapAsync()
But discovered that some of the images coming in are rotated, so experimenting I came up with this:
$BmTf = [BitmapTransform]::new()
$BmTf.Rotation = [BitmapRotation]::None
# $BmTf.Rotation = [BitmapRotation]::Clockwise90Degrees
# $BmTf.Rotation = [BitmapRotation]::Clockwise180Degrees
# $BmTf.Rotation = [BitmapRotation]::Clockwise270Degrees
$AsyncTask = $BitmapDecoder.GetSoftwareBitmapAsync(
[BitmapPixelFormat]::Bgra8,
[BitmapAlphaMode]::Ignore,
$BmTf,
[ExifOrientationMode]::IgnoreExifOrientation,
[ColorManagementMode]::DoNotColorManage
)
While it does work, I'm not familiar BitmapPixelFormat, or the other parameters. The documentation for GetSoftwareBitmapAsync() doesn't appear to give any hints on what the default value it is using for BitmapPixelFormat.
Does anyone know the best values to pass to the version of GetSoftwareBitmapAsync() that takes 5 parameters to mimic the version of GetSoftwareBitmapAsync() that takes 0 parameters?
EDIT:
Just found out that trying [BitmapPixelFormat]::Unknown causes this error:
Exception calling "GetSoftwareBitmapAsync" with "5" argument(s): "The
parameter is incorrect. Windows.Graphics.Imaging: The bitmap pixel
format is unsupported."
But no errors with [BitmapPixelFormat]::Bgra8.
I don't know why GetSoftwareBitmapAsync doesn't like [BitmapPixelFormat]::Unknown, but here is the solution I found.
I need to first load the image to see if it needs rotating. That is done with the original command:
$AsyncTask = $BitmapDecoder.GetSoftwareBitmapAsync()
$SoftwareBitmap = GetAsync( $AsyncTask, ([SoftwareBitmap]) )
Then extract its BitmapPixelFormat:
$BitmapPixelFormat = $SoftwareBitmap.BitmapPixelFormat
And then use $BitmapPixelFormat for all calls to the 5 parameter version of GetSoftwareBitmapAsync().

Keep getting 'Unexpected identifier' when running tests

I am trying to copy a tutorial for a Wordle solving bot but its just not going well. whenever I try to run a test on the code it doesn't work at certain points, I'll either get 'Uncaught SyntaxError: Unexpected identifier'. I'm doing this on UIlicious.
Here's what I've got so far:
I.goTo("https://www.powerlanguage.co.uk/wordle/")
I.click("reject")
I.see("Guess the Wordle")
I.click('/html/body', 40, 80)
let guessWord = null
for(Let r=0 ; r<6 ; ++r) {
guessWord = solver.suggestWord(gameState)
I.type(guessWord);
I.pressEnter()
I.wait(2)
}
let rowList = document.querySelector("game-app").shadowRoot. //
querySelector("game-theme-manager"). //
querySelector("#board").querySelectorAll("game-row");
you are probably referring to the article I wrote here : https://uilicious.com/blog/automate-wordle-via-uilicious/
This test script, is designed specifically to use uilicious.com, so you will need to edit and run it through the platform.
You can do so via the snippet here : https://snippet.uilicious.com/test/public/N5qZKraAaBsAgFuSN8wxCL
If you have syntax error there, do let me know with a snippet link - and I will try to help you respectively.
Also the snippet you provided so far, excludes the "solver" class which was initialised much further down.

How to use jeromq in MATLAB

jeromq is a Java implementation of libzmq. I have a .jar file created from the jeromq source. However, I'm unable to call a class in jeromq from MATLAB. I've used addjavaclasspath and addjavalibrarypath but am still not able to get it working. Does anyone have a simple working example in MATLAB?
I've added the answer here as for reference in case anyone else is interested.
% Author : Dheepak Krishnamurthy
% License : BSD 3 Clause
import org.zeromq.ZMQ;
ctx = zmq.Ctx();
socket = ctx.createSocket(ZMQ.REP);
socket.bind('tcp://127.0.0.1:7575');
message = socket.recv(0);
json_data = native2unicode(message.data)';
message = zmq.Msg(8);
message.put(unicode2native('Received'));
socket.send(message, 0);
socket.close()
My Matlab 9.0.0.341360 (R2016a) wanted the following code instead of import above:
javaclasspath('/path/to/jar/jeromq-0.4.3-SNAPSHOT.jar')
import org.zeromq.*
The rest worked fine.
Here is what I had to do to get things working.
javaclasspath('jeromq-0.5.1.jar')
import org.zeromq.*;
%subscribe to ZMQ feed
context = ZContext();
socket = context.createSocket(ZMQ.SUB);
success = false;
while(~success)
success = socket.connect('tcp://127.0.0.1:5996');
end
socket.subscribe("");
socket.setTCPKeepAlive(1);
%receive a message
message = socket.recv(0); %nonblocking receive uses argument (1)
%when done
socket.close();

simulink - GetSet Custom Storage Class

I am having a model which takes two input & multiplies them & give the output.
output_1 = input_1 * input_2
I have declared my simulink signals as CustomStorageClass= GetSet
input_1 = Simulink.Signal;
input_1.CoderInfo.StorageClass = 'Custom';
input_1.CoderInfo.CustomStorageClass = 'GetSet';
input_1.CoderInfo.CustomAttributes.GetFunction = 'Get_input_1';
input_1.CoderInfo.CustomAttributes.SetFunction = 'Set_input_1';
input_1.CoderInfo.CustomAttributes.HeaderFile = 'signals.h';
input_2 = Simulink.Signal;
input_2.CoderInfo.StorageClass = 'Custom';
input_2.CoderInfo.CustomStorageClass = 'GetSet';
input_2.CoderInfo.CustomAttributes.GetFunction = 'Get_input_2';
input_2.CoderInfo.CustomAttributes.SetFunction = 'Set_input_2';
input_2.CoderInfo.CustomAttributes.HeaderFile = 'signals.h';
output_1 = Simulink.Signal;
output_1.CoderInfo.StorageClass = 'Custom';
output_1.CoderInfo.CustomStorageClass = 'GetSet';
output_1.CoderInfo.CustomAttributes.GetFunction = 'Get_output_1';
output_1.CoderInfo.CustomAttributes.SetFunction = 'Set_output_1';
output_1.CoderInfo.CustomAttributes.HeaderFile = 'signals.h';
Now I am trying to convert my model to code using simulink coder.
In code generation setting of the model i have selected ert.tlc file in the system target file settings.
But the generated code does not have a Get_input_1() or Get_input_2() call like shown in this link.
http://www.mathworks.com/help/ecoder/ug/getset-custom-storage-classes.html
What i have missed in the setting. Please suggest
I know you probably already solved this issue, but I have also seen this behavior before.
Sometimes MATLAB does not update the header files correctly. If you had set a different configuration for your variable and then made a change involving the header files, I would recommend erasing the *_ert_rtw and slprj folders (they will appear again). It is similar to doing a "Make clean" operation, to ensure that everything is brand new.

Resource Not Found Exception in pyglet

I'm using Python 2.6.6 and pyglet 1.1.4. In my "Erosion" folder, I have "Erosion.py" and a folder named "Images." Inside images, there are .png images. One image is named "Guard.png."
In "Erosion.py" there is a segment that goes like so:
pyglet.resource.path = ['Images']
pyglet.resource.reindex()
self.image = pyglet.resource.image('%s%s' % (character, '.png'))
When I run this, I am given
File "C:\Python26\lib\site-packages\pyglet\resource.py", line 394, in file raise ResourceNotFoundException(name)
ResourceNotFoundException: Resource "Guard.png" was not found on the path. Ensure that the filename has the correct captialisation.
I have tried changing the path to ['./Images'] and ['../Images']. I've also tried removing the path and the reindex call and putting Erosion.py and Guard.png in the same folder.
This is what i do to be able to load resources:
pyglet.resource.path = ['C:\\Users\\myname\\Downloads\\temp']
pyglet.resource.reindex()
pic = pyglet.resource.image('1.jpg')
texture = pic.get_texture()
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
texture.width = 960
texture.height = 720
texture.blit(0, 0, 0)
try this
pyglet.image.load('path/to/image.png')
If the relative path is not working you can try with the absolute path using the os module.
import pyglet
import os
working_dir = os.path.dirname(os.path.realpath(__file__))
pyglet.resource.path = [os.path.join(working_dir,'Images')]
pyglet.resource.reindex()
image = pyglet.resource.image('character.png'))
It's better to use the os.path.join method instead of writing it as a string for a better cross-platform support.
I get a problem like this using pyglet and pyscripter.(the text editor) In order for the file to be found I have to restart the editor before running the program.
This might be a problem with pyscripter however.
It is worth looking into: http://pyglet.readthedocs.io/en/pyglet-1.3-maintenance/programming_guide/resources.html
You should include all the directories into:
pyglet.resource.path = [...]
Then pass the ONLY the file name when you call:
pyglet.resource.image("ball_color.jpeg")
Try:
import os
import pyglet
working_dir = os.path.dirname(os.path.realpath(__file__))
image_dir = os.path.join(working_dir, 'images')
sound_dir = os.path.join(working_dir, 'sound')
print working_dir
print "Images are in: " + image_dir
print "Sounds are in: " + sound_dir
pyglet.resource.path = [working_dir, image_dir, sound_dir]
pyglet.resource.reindex()
try:
window = pyglet.window.Window()
image = pyglet.resource.image("ball_color.jpeg")
#window.event
def on_draw():
window.clear()
image.blit(0, 0)
pyglet.app.run()
finally:
window.close()
The use of try and finally are not necessary, but they are recommended. You might end up with a lot of open windows and pyglet back processes if you don't close the window when there are errors.
pyglet 1.4.4 format: HUD_img = pyglet.resource.image('ui\ui_gray_block_filled.png')
pyglet 1.4.8 format: HUD_img = pyglet.resource.image('ui/ui_gray_block_filled.png')
I was using pyglet 1.4.4 and was able to use this the first format.
After upgrading to pyglet 1.4.8 I had the error: pyglet.resource.ResourceNotFoundException: Resource "your_resource_path" was not found on the path.
Switching to the 2nd format with forward slashes solved this issue for me. Not sure why this change was made...I'm sure there was a good reason for it.