"Invalid argument at position 1" error in Matlab and Simulink - matlab

I'm coding an RL environment using Matlab and simulink and I'm following the code set out in the following example from mathworks (https://uk.mathworks.com/help/reinforcement-learning/ug/create-simulink-environment-and-train-agent.html)
However for some reason when I'm defining my 'featureInputLayer' I keep getting an error stating that there is an invalid argument at position 1. I'm not certain on what this means, I've seen a few other questions asked here on similar topics but haven't been able to find an answer.
Here's the code where I'm getting an error (the featureInputLayer of StatePath):
statePath = [
featureInputLayer(numObservations,'Normalization','none','Name','State')
fullyConnectedLayer(50,'Name','CriticStateFC1')
reluLayer('Name','CriticRelu1')
fullyConnectedLayer(25,'Name','CriticStateFC2')];
actionPath = [
featureInputLayer(numActions,'Normalization','none','Name','Action')
fullyConnectedLayer(25,'Name','CriticActionFC1')];
commonPath = [
additionLayer(2,'Name','add')
reluLayer('Name','CriticCommonRelu')
fullyConnectedLayer(1,'Name','CriticOutput')];
Any help would be greatly appreciated :D

Related

Error about C_outflow[] when using FluidPort

i'm noob for modelica and developing the Heat Exchanger model.
I did input
air_in.X_outflow[1]=1;
air_out.X_outflowp[1]=1;
coolant_in.X_outflow[1]=1;
coolant_out.X_outflow[1]=1;
but I encountered some errors like captures below.
First, I don't know what is the physical meaning of C_outflow. I could find that C_outflow = c_i/m
and m is the mass of the fluid, but couldn't find the meaning of c_i.
Second, I've just tried to input the value 0~1 as the description said, but encountered the error message above. I think the value has not been input to the C_outflow array but I'm not sure.
Please reply to anyone who can figure out these problems... Thank you to all of you.
model Staggered_HX
A complete model would be helpful - but attempting to answer anyway:
The C-array is an array of trace substances, and there are normally no trace substances; whereas the X-array is the array of normal substances - which must contain some elements.
For the C-array it would thus be: air_in.C_outflow=zeros(0); (where zeros(0) creates an empty vector - corresponding to no trace substabces), but I don't see how that relates to the equations above with air_in.X_outflow[1]=1;

Editing the Code of a "MATLAB Function" Block in Simulink Programmatically

I'd like to create a simple Simulink model containing a "MATLAB Function" block programmatically -- i.e. using Matlab code.
Thanks to this guide, I've managed to create a new model containing the block:
open_system(new_system('my_system'))
add_block('simulink/User-Defined Functions/MATLAB Function', 'my_system/my_func')
Usually, in order to edit the "MATLAB Function" block's code, one has to "open" the block by double-clicking on it then entering the new code.
However, I would like to set that code programmatically using e.g. set_param() or any relevant function.
For instance, to set the following as the block's code:
function y = fcn(v)
%#codegen
y = 2 * u;
I would like to use something like:
set_param('my_system/my_func', 'Script',...
'function y = fcn(u)\n%#codegen\n\ny = 2 * u;'...
);
I've looked at the output of get_param('my_system/my_func', 'ObjectParameters') and tried to guess which parameter might be used to set the block's function code: So far, I couldn't find any. Therefore, my question is:
Q: Is it possible, using only Matlab commands, to set the code of a "MATLAB Function" block in Simulink?
(As requested by #Ander Biguri, I've moved a solution that worked for me to a separete answer post. If anyone has an alternative/better approach, please feel free to post it as well)
Well, it seems that this question was asked here before. (perhaps formulated differently though?) I've managed to solve my issue using the following code:
sf = sfroot()
block = sf.find('Path','my_system/my_func','-isa','Stateflow.EMChart');
block.Script = sprintf('function y = fcn(u)\n%%#codegen\n\ny = 2 * u;')

runtime error in bundle adjustment example - matlab

I asked it in MATLAB forums but didnt get a response. Hoping someone can answer the question here:
I tried using Bundle Adjustment example at https://www.mathworks.com/help/vision/ref/bundleadjustment.html#inputarg_xyzPoints
However, I get an error: "Error using getPrmDflt (line 47) odd number of parameters in prm Error in bundleAdjustment (line 49) getPrmDflt( varargin,{ 'KMask', [], 'nItr', 500, ..."
at this line: [xyzRefinedPoints,refinedPoses] = bundleAdjustment(xyzPoints,pointTracks,cameraPoses,cameraParams);
After looking more into it the input to getPrmDflt is totally different that what the function expects. Is there some bug or wrong function call in bundle adjustment code?
it was an error from my side. I had downloaded Vincent's MATLAB toolbox a couple of years ago for use and it had a bundleAdjustment function call that overrode the MATLAB function.

How can I run createOptimProblem in matlab?

My question is a little bit stupid, but still, I would like someone who can help me if he/she face the same problem as me.
I copy the codes directly from MATLAB mathwork:
anonrosen = #(x)(100*(x(2) - x(1)^2)^2 + (1-x(1))^2);
opts = optimoptions(#fmincon,'Algorithm','interior-point');
problem = createOptimProblem('fmincon','x0',randn(2,1),...
'objective',anonrosen,'lb',[-2;-2],'ub',[2;2],'options',opts);
However, it gives the following error message:
Undefined function 'createOptimProblem' for input arguments of type 'optim.options.Fmincon'.
createOptimProblem should be a built-in function, but with the presence of the error message, I wonder if I need to declare sth before using createOptimProblem, what should I do?
I am using R2013a version

wordcloud package: get "Error in strwidth(...) : invalid 'cex' value"

I am using the tm and wordcloud packages in R 2.15.1.
I am trying to make a word cloud from a DTM. Here is the code:
library(wordcloud)
thedtmsparse = inspect(sparse)
trymatrix = t(thedtmsparse)
colnames(trymatrix) = c()
comparison.cloud(trymatrix, max.words=15, random.order=FALSE)
I get the following error from the last command:
Error in strwidth(words[i], cex = size[i], ...) : invalid 'cex' value
I have used the same code on another DTM where it worked fine and I got the word cloud.
Can somebody tell me a fix for the error?
Ravi
You haven't provided reproducible code (probably a big reason no one answered your question), so I can only venture to guess what the problem might be.
I faced this same error, so I'll share my experience. The problem was I had NA's instead of 0's in my term document matrix. Simply fixing that fixed that problem.